gcc: Function Prototypes
1
1 6.38 Prototypes and Old-Style Function Definitions
1 ==================================================
1
1 GNU C extends ISO C to allow a function prototype to override a later
1 old-style non-prototype definition. Consider the following example:
1
1 /* Use prototypes unless the compiler is old-fashioned. */
1 #ifdef __STDC__
1 #define P(x) x
1 #else
1 #define P(x) ()
1 #endif
1
1 /* Prototype function declaration. */
1 int isroot P((uid_t));
1
1 /* Old-style function definition. */
1 int
1 isroot (x) /* ??? lossage here ??? */
1 uid_t x;
1 {
1 return x == 0;
1 }
1
1 Suppose the type 'uid_t' happens to be 'short'. ISO C does not allow
1 this example, because subword arguments in old-style non-prototype
1 definitions are promoted. Therefore in this example the function
1 definition's argument is really an 'int', which does not match the
1 prototype argument type of 'short'.
1
1 This restriction of ISO C makes it hard to write code that is portable
1 to traditional C compilers, because the programmer does not know whether
1 the 'uid_t' type is 'short', 'int', or 'long'. Therefore, in cases like
1 these GNU C allows a prototype to override a later old-style definition.
1 More precisely, in GNU C, a function prototype argument type overrides
1 the argument type specified by a later old-style definition if the
1 former type is the same as the latter type before promotion. Thus in
1 GNU C the above example is equivalent to the following:
1
1 int isroot (uid_t);
1
1 int
1 isroot (uid_t x)
1 {
1 return x == 0;
1 }
1
1 GNU C++ does not support old-style function definitions, so this
1 extension is irrelevant.
1