`char' parameters: a follow-up/summary ( Long - but worth it :-) )

David MacKenzie edf at rocky2.rockefeller.edu
Fri Sep 9 15:52:25 AEST 1988


K&R (original), p.42:
	Since a function argument is an expression, type conversions
	also take place when arguments are passed to functions: in
	particular, char and short become int, and float becomes double.
	This iswhy we have declared function arguments to be int and
	double even when the function is called with char and float.

This is one of the big reasons that K&R C is not considered by some to
be as good as FORTRAN for floating-point work; you can't have a function
that takes a float or a char as an argument, which would be more
efficient if that's all the precision that you need.  I have been under
the impression that ANSI standard C programs behave in the same way in
the absence of a prototype, but that if you use prototypes, you can
actually pass char, short and float arguments to a function without any
type conversion.

David MacKenzie

David MacKenzie
Environmental Defense Fund
edf at rocky2.rockefeller.edu (...rutgers!cmcl2!rocky2!edf)



More information about the Comp.lang.c mailing list