[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNU coding standards
From: |
Arsen Arsenović |
Subject: |
Re: GNU coding standards |
Date: |
Wed, 09 Oct 2024 23:11:14 +0200 |
"Alfred M. Szmidt" <ams@gnu.org> writes:
> * K&R C compilers (i.e. compilers that don't support ANSI C from 1989)
> are not in use any more.
>
> Yeah they are. I maintain plenty of such code.
>
> In Gnulib, we have dropped support for such
> compilers in 2011, and no one complained.
>
> No, but I had to fix bunch of such code so that it works with legacy.
I think that's a better trade-off than writing non-standard code and
then having to fix that today.
> * The most recent gcc and clang compilers, when used with option
> -std=gnu23,
> warn about K&R C functions definitions:
>
> Sorry, but 2023 is just last year, and what clang does is more or less
> irrelevant.
Yet these have been out of the discouraged since long before 2023.
And I'm more inclined to care about what clang does than whatever
compiler would require such antiquated practices.
> This option -std=gnu23 will become the default in the future, like
> -std=gnu99 and later -std=gnu11 became the default.
>
> Therefore the harm of this section is that it suggests a code style
> that we know is not future-proof.
>
> It is plenty future proof, seeing that it has worked for much longer
> than the years elapsed since 2023.
I'm not sure how the former implies the latter in that sentence.
> There is literally no harm in keeping a section that is _optional_.
> The GNU Coding standards are not mandatory, enforced, or otherwise
> enforced so to call this harm is absurd.
I think Bruno put it well.
Also, keeping this around at least wastes the readers time with poor
advice that they'll have to think about for no reason (or, if especially
unlucky, follow). The dev_t paragraph later in the file also shows a
decent example of this going wrong. I also wonder if this technique
breaks with LTO.
> Feel free to suggest a patch instead of exaggeration though.
Here's a patch:
diff --git a/doc/standards.texi b/doc/standards.texi
index 30592c65..bf7fd9c2 100644
--- a/doc/standards.texi
+++ b/doc/standards.texi
@@ -407,67 +407,6 @@ @node Standard C
use these features if GCC supports them, when they give substantial
benefit.
-However, it is easy to support pre-standard compilers in most programs,
-so if you know how to do that, feel free.
-
-@cindex function prototypes
-To support pre-standard C, instead of writing function definitions in
-standard prototype form,
-
-@example
-int
-foo (int x, int y)
-@dots{}
-@end example
-
-@noindent
-write the definition in pre-standard style like this,
-
-@example
-int
-foo (x, y)
- int x, y;
-@dots{}
-@end example
-
-@noindent
-and use a separate declaration to specify the argument prototype:
-
-@example
-int foo (int, int);
-@end example
-
-You need such a declaration anyway, in a header file, to get the benefit
-of prototypes in all the files where the function is called. And once
-you have the declaration, you normally lose nothing by writing the
-function definition in the pre-standard style.
-
-This technique does not work for integer types narrower than @code{int}.
-If you think of an argument as being of a type narrower than @code{int},
-declare it as @code{int} instead.
-
-There are a few special cases where this technique is hard to use. For
-example, if a function argument needs to hold the system type
-@code{dev_t}, you run into trouble, because @code{dev_t} is shorter than
-@code{int} on some machines; but you cannot use @code{int} instead,
-because @code{dev_t} is wider than @code{int} on some machines. There
-is no type you can safely use on all machines in a non-standard
-definition. The only way to support non-standard C and pass such an
-argument is to check the width of @code{dev_t} using Autoconf and choose
-the argument type accordingly. This may not be worth the trouble.
-
-In order to support pre-standard compilers that do not recognize
-prototypes, you may want to use a preprocessor macro like this:
-
-@example
-/* Declare the prototype for a general external function. */
-#if defined (__STDC__) || defined (WINDOWSNT)
-#define P_(proto) proto
-#else
-#define P_(proto) ()
-#endif
-@end example
-
@node Conditional Compilation
@section Conditional Compilation
--
Arsen Arsenović
signature.asc
Description: PGP signature
- GNU coding standards, Martin D Kealey, 2024/10/08
- Re: GNU coding standards, Alfred M. Szmidt, 2024/10/09
- Re: GNU coding standards, Bruno Haible, 2024/10/09
- Re: GNU coding standards, Collin Funk, 2024/10/09
- Re: GNU coding standards, Alfred M. Szmidt, 2024/10/09
- Re: GNU coding standards,
Arsen Arsenović <=
- Re: GNU coding standards, Alfred M. Szmidt, 2024/10/10
- Re: GNU coding standards, Arsen Arsenović, 2024/10/13
- Re: GNU coding standards, Alfred M. Szmidt, 2024/10/13
- Re: GNU coding standards, Arsen Arsenović, 2024/10/14
- Re: GNU coding standards, Richard Stallman, 2024/10/16
- Re: GNU coding standards, Arsen Arsenović, 2024/10/19
- Re: GNU coding standards, Martin D Kealey, 2024/10/13
- Re: GNU coding standards, Richard Stallman, 2024/10/13
- Re: GNU coding standards, Richard Stallman, 2024/10/13
- Re: GNU coding standards, Bruno Haible, 2024/10/14