Message ID | patch-4.5-17c2a0d88e8-20221007T092505Z-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | CodingGuidelines: various C99 updates | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > The C99 section of the CodingGuidelines is a good overview of what we > can use, but is sorely lacking in what we can't use. Something that > comes up occasionally is the portability of %z. > > Per [1] we couldn't use it for the longest time due to MSVC not > supporting it, but nowadays by requiring C99 we rely on the MSVC > version that does, but we can't use it yet because a C library that > MinGW uses doesn't support it. > > 1. https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/ > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > --- > Documentation/CodingGuidelines | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines > index f9affc4050a..893f960231f 100644 > --- a/Documentation/CodingGuidelines > +++ b/Documentation/CodingGuidelines > @@ -235,6 +235,13 @@ For C programs: > . since late 2021 with 44ba10d6, we have had variables declared in > the for loop "for (int i = 0; i < 10; i++)". > > + New C99 features that we cannot use yet: > + > + . %z and %zu as a printf() argument for a size_t (the %z being for > + the POSIX-specific ssize_t). Instead you should use > + printf("%"PRIuMAX, (uintmax_t)v); These days the MSVC version we > + rely on supports %z, but the C library used by MinGW does not. > + Good. s/; These days/; these days/, though.
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index f9affc4050a..893f960231f 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -235,6 +235,13 @@ For C programs: . since late 2021 with 44ba10d6, we have had variables declared in the for loop "for (int i = 0; i < 10; i++)". + New C99 features that we cannot use yet: + + . %z and %zu as a printf() argument for a size_t (the %z being for + the POSIX-specific ssize_t). Instead you should use + printf("%"PRIuMAX, (uintmax_t)v); These days the MSVC version we + rely on supports %z, but the C library used by MinGW does not. + - Variables have to be declared at the beginning of the block, before the first statement (i.e. -Wdeclaration-after-statement).
The C99 section of the CodingGuidelines is a good overview of what we can use, but is sorely lacking in what we can't use. Something that comes up occasionally is the portability of %z. Per [1] we couldn't use it for the longest time due to MSVC not supporting it, but nowadays by requiring C99 we rely on the MSVC version that does, but we can't use it yet because a C library that MinGW uses doesn't support it. 1. https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- Documentation/CodingGuidelines | 7 +++++++ 1 file changed, 7 insertions(+)