_NARGS - size of arguments passed to the function.

(Not ANSI but found on many systems)


i = _nargs();


int i;
indicates the size of the arguments passed to the current function.


"_nargs" returns the number of words of stack space occupied by the arguments passed to the current function. If the function was not called with a standard call, "_nargs" returns -1.

The name "_nargs" comes from implementations of C on systems where each argument occupied one machine word. Therefore the number of machine words equalled the number of arguments. However, this is not true under GCOS8 (and on many other modern computers). For example, consider the following function call.


If "_nargs" was called inside "fun", it would return the integer 6. Why? The 'a' and 'b' only take up one byte each, but character data is converted to integer when being passed. Thus in the call they take up one word each. The integer 1 takes up another word. This makes a total of three words so far. The 3.2 is passed using double precision, and must therefore be aligned on a double word boundary; thus the compiler puts in an unused filler word on the stack and then puts in the 3.2 occupying two words. The total stack size is therefore six words, even though only four arguments are passed.


This function may return different answers on different hardware platforms. Therefore, its use limits program portability.

Copyright © 1996, Thinkage Ltd.