Solaris 2.3, cc: SC3.0 15 Dec 1993
What's the rationale behind the following compiler behavior?
Given the following C file..
-----------------------------------------------------------------
extern int foo(short n);
int
foo(n)
short n;
{
return 0;
main() {}Quote:}
-----------------------------------------------------------------
You get the follow warnings when compiling with -Xa:
"foo.c", line 5: warning: identifier redeclared: foo
current : function() returning int
previous: function(short) returning int : "foo.c", line 1
"foo.c", line 6: warning: Prototype mismatch in arg 1 for function foo:
function : old style declaration short promoted to int
prototype: short
Here's the explanation from the Answerbook:
For compatability reasons, foo's arguments must be promoted
according to the default argument promotions, which is how they
were promoted before the existence of function prototypes.
Therefore, the value that must be passed to foo is an int although
the function will only use the char [short in my example] part
of the value.
This explanation still leaves me confused as to why the compiler
behaves this way. Can someone explain in more detail what
compatability reasons justify this compiler behavior?
-Jon