Emmanuel Delahaye wrote:
Walter Roberson wrote on 26/04/05 :
memset() dates from the time when characters and shorts
were always promoted to integers for function calls.
Is it different now ?
Yes, in the presence of a prototype.
int knr(x) short x; { ... }
int c9x(short x) { ... }
...
short s = 42;
knr(s);
c90(s);
In the call to knr(), `s' is promoted to int and passed
to the function, where it is then "demoted" back to short
again. In the call to c9x(), `s' is passed unchanged (or
"as if unchanged"), without promotion/demotion.
This leads to a nasty little trap that occasionally
snags people who are writing C9x prototypes for K&R-style
functions, without changing the function definitions (a
practice of dubious merit). The correct C9x declaration
for knr() is not `int knr(short)' but `int knr(int)', and
a too-mechanical prototype generator that produced the
former would be wrong.
--
Er*********@sun.com