Function Argument Conversions

C If a function declaration is present and includes declared argument types, the compiler performs type checking. If no function declaration is visible when a function is called, or when an expression appears as an argument in the variable part of a prototype argument list, the compiler performs default argument promotions or converts the value of the expression before passing any arguments to the function. The automatic conversions consist of the following:

C When compiled using a compiler option that allows the GNU C semantics, a function prototype may override a later K&R nonprototype definition. This behavior is illegal in ISO C. Under ISO C, the type of function arguments after automatic conversion must match that of the function prototype.

int func(char);     /* Legal in GCC, illegal in ISO C                         */
 
int func(ch)        /* ch is automatically promoted to int,                   */
   char ch;         /* which does not match the prototype argument type char  */
{ return ch == 0;}
 
 
int func(float);     /* Legal in GCC, illegal in ISO C                         */
 
int func(ch)         /* ch is automatically promoted to double,                */
   float ch;         /* which does not match the prototype argument type float */
{ return ch == 0;}
 

C++Function declarations in C++ must always specify their parameter types. Also, functions may not be called if it has not already been declared.

Related References

IBM Copyright 2003