c - Why does a function prototype with an empty argument list conflicts with one that has a char argument? -
with the code given below -std = C11 with complaints about both the clang and the controversial types for the GCC foo .
int foo (); Int main (zeros) {returns af (0); } Int foo (char a) {return a; }
According to the answer, in (Old?) C standards have been typed when no variable type was given. However, the C11 standard draft (), volume 6.7.6.3, $ 14 says that
An empty list in the function manifestation that is not part of the definition of that function, specifies that There is no information in the number or type of parameters supplied.
I conclude that the above code should actually be valid. Or am I missing some other relevant part of the standard?
C 2011 (N1570) 6.7.6.3 15:
Be consistent with two function types, both will specify the corresponding return type. In addition, parameter type lists, if both are present, then agree with the use of the number of standards and the oval terminator; In the same parameter, if there is a type of parameter type, and another type is specified by a function declarator which is not part of the function definition and has a blank identifier list, in the parameter list, the alipis terminator and No type will be associated with each parameter that will be the result of default logic propaganda application . ... [emphasis added.]
Basically, the reason for this is that, if you declare the function Then, if you later will not match the definition code char
is promoted to int
, hence the char a
is not compatible with an empty list. will be an
; int foo (); Int foo (int a); Permission is granted.
int foo ()
and then call it, int foo (3) int foo (3)
is called as int foo (int)
. inti fu (four)
. In many implementations, one can put a char
and a int
in a single function to be called a function, but a C implementation can do something different float
and double
will be a big conflict.
Comments
Post a Comment