Reputation: 1513
My understanding of type promotion of function arguments in C, is that, if I call a non prototyped function with an argument of type char
or short
, it will get promoted to an int
.
Question: What if I call it with a long
as argument, and sizeof(long) > sizeof(int)
?
If the parameter is passed as a long
, why not choosing long
as the type to which all the integral parameters should be promoted to? isn't the reason behind type promotion of arguments, is to make compilers simpler to write, by making the parameters pushed on the stack all the same length, so that the runtime system needs only to know the number of parameters, and not to bother with their sizes?
Upvotes: 1
Views: 123
Reputation: 1
why not choosing
long
...
Because long
didn't exist when the "promote everything to int
" design was created.
Now, changing the default promotion rules will break just about every bit of extant C code as it would also change the behavior of calls such as printf()
and open()
.
Any varargs-type function would be impacted - which includes open()
. There are probably other, more subtle issues, but "breaking just about everything" is sufficient reason to not do it.
Upvotes: 3