Contents|Index|Previous|Next
 Prototypes and old-style function definitions   

GNU C extends ANSI C to allow a function prototype to override a later old-style non-prototype definition. Consider the following example. Suppose the type, uid_t, happens to be short. ANSI 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 ANSI 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 previous example is equivalent to the following:

GNU C++ does not support old-style function definitions, so the previous example’s extension is irrelevant.

Top|Contents|Index|Previous|Next