Variadic argument functions

Doug Gwyn gwyn at brl-smoke.ARPA
Sat Apr 16 07:49:33 AEST 1988


In article <253 at teletron.UUCP> andrew at teletron.UUCP (Andrew Scott) writes:
>	(*vector)(arg);
>	void funcA(arg)
>	void funcB()

For maximal portability, your functions all need to have identical
interfaces, either precisely the same number and types of arguments
and return value, or all variadic arguments (in which case there must
still be at least one fixed "anchor" argument of the same type).

On a large number of architectures, though, you can get away with
your current approach.

>in the range 0..1000.  Should the argument be of type short, to emphasize the
>range of the argument?  Or, should I use ints everywhere and simply document
>the range of acceptable argument values.  How about function return values?

The main reason most existing functions use int is that that was the
type to which all smaller integral types were widened at the function
interface.  This widening is not required for ANSI C when prototypes
are used.

The best style would be to use the appropriate type AND document the
interface.  The safest thing to do is to use int anyway, because some
compilers may incorrectly handle other function definitions (they
aren't supposed to mishandle these, but it's been known to happen).



More information about the Comp.lang.c mailing list