J. J. Farrell said:
Michael B. said:
I tend to use rather descriptive names for parameters, so the old style of
declaration appeals to me, as I can keep a declaration within 80 chars:
void * newKlElem (frame_size,num_blocks,num_frames,frame_locator)
size_t frame_size;
unsigned short num_blocks;
unsigned short num_frames;
Kl_frame_locator *locator;
{
[...]
The example you give is also invalid. Unless you have a prototype
in scope at the time of the call, it is not possible for your
function to receive parameters of type <unsigned short>. They will
have been promoted at the time of the call to be either <int> or
<unsigned int> depending on the type sizes in the implementation -
so to make your version portable, you need some ugly compile-time
duplication of the parameters in the function definition, or you
need to explicitly cast the parameters to an appropriate type in
each call.
This is the second time this piece of misinformation has
cropped up in this thread. I can only conclude that people
have become so accustomed to prototyped functions (that's
understandable; they *are* better) that they've completely
forgotten how old-style functions worked.
For the record:
- Pre-Standard C is/was a language without function
prototypes, in which the O.P.'s style of function
definition is/was the only possible style, and
- In pre-Standard C it is/was possible to write a
function with promotable argument types like `char'
and `short' and `float', and to call such functions
even though the supplied values are/were subject to
promotion at the point of call, and
- Standard C retains the pre-Standard function style,
augmenting rather than supplanting it, and
- Pre-Standard functions and calls work in Standard C
just as they do/did in pre-Standard C.
Reference: ISO/IEC 9899:1999 (E), Section 6.5.2.2,
paragraph 6, sentences 1, 2 and 5:
If the expression that denotes the called function has
a type that does not include a prototype, the integer
promotions are performed on each argument, and arguments
that have type float are promoted to double. These are
called the default argument promotions. [...] If the
function is defined with a type that does not include a
prototype, and the types of the arguments after promotion
are not compatible with those of the parameters after
promotion, the behavior is undefined, [...]
In short, the types of the promoted arguments need not match the
types of the formal parameters, they need to match the *promoted*
types of those parameters.
People seem to have lost sight of the fact that although
Standard C was born in 1989, C itself had been around for some
dozens of weeks before that -- and yes, during that Paleozoic
time, young 'uns, it *was* possible to write C programs. Been
there, done that -- don't want to go back. Use prototypes.