From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/gcc~13/function-prototypes.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 devdocs/gcc~13/function-prototypes.html (limited to 'devdocs/gcc~13/function-prototypes.html') diff --git a/devdocs/gcc~13/function-prototypes.html b/devdocs/gcc~13/function-prototypes.html new file mode 100644 index 00000000..04da0a63 --- /dev/null +++ b/devdocs/gcc~13/function-prototypes.html @@ -0,0 +1,30 @@ +

6.40 Prototypes and Old-Style Function Definitions ¶

GNU C extends ISO C to allow a function prototype to override a later old-style non-prototype definition. Consider the following example:

/* Use prototypes unless the compiler is old-fashioned.  */
+#ifdef __STDC__
+#define P(x) x
+#else
+#define P(x) ()
+#endif
+
+/* Prototype function declaration.  */
+int isroot P((uid_t));
+
+/* Old-style function definition.  */
+int
+isroot (x)   /* ??? lossage here ??? */
+     uid_t x;
+{
+  return x == 0;
+}
+

Suppose the type uid_t happens to be short. ISO C does not allow this example, because subword arguments in old-style non-prototype definitions are promoted. Therefore in this example the function definition’s argument is really an int, which does not match the prototype argument type of short.

This restriction of ISO C makes it hard to write code that is portable to traditional C compilers, because the programmer does not know whether the uid_t type is short, int, or long. Therefore, in cases like these GNU C allows a prototype to override a later old-style definition. More precisely, in GNU C, a function prototype argument type overrides the argument type specified by a later old-style definition if the former type is the same as the latter type before promotion. Thus in GNU C the above example is equivalent to the following:

int isroot (uid_t);
+
+int
+isroot (uid_t x)
+{
+  return x == 0;
+}
+

GNU C++ does not support old-style function definitions, so this extension is irrelevant.

+

+ © Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
+ https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Function-Prototypes.html +

+
-- cgit v1.2.3