HELP! What's wrong with my program? (Arg passing)
Basile STARYNKEVITCH
basile at soleil.cea.fr
Thu Mar 28 07:35:00 AEST 1991
Your code is implicitly built on the assumption that arguments are passed
on a stack (such as Mc680x0 machines, eg. Sun3s). Actually this is false
on many RISC machines, such as Sun4s. On SPARC machines, arguments are
passed in registers (each calling frame is actually a set of registers -
there are 32 sets of 24 (overlapping) registers), so calls (especially to
leaf routines) is really fast. The system flushs the register set to the
(memory) stack when it is full. On Vaxen, a calling frame is supported by
hardware (on the calling stack). By the way, your code is neither lint
nor Ansi-C (or C++) compliant.
For this reason, varargs (with setjmp, etc) facilities are peculiar to
each compiler&machine (and their interface should be and is normalized in
Ansi-C or K&R-C or C++). On Sun3, varargs are plain C (machine and
compiler dependant) macros. On Sun4, varargs use special identifiers
__builtin_va_alist & __builtin_va_arg_incr (see /usr/include/varargs.h)
known by the compiler. On Vaxen, varargs call a special routine (assembly
coded in libc.a).
By the way, C is lacking of the varargs reciprocial: calling a routine
(given by its adress) with a variable sized list of arguments. More
specifically, i'm seeking for a "varapply" capability to call a routine
whose argument list is known at run time - e.g. given by a null terminated
array of (argument size, argument adress) tuples.
Basile STARYNKEVITCH
Commissariat a l' Energie Atomique
DRN/DMT/SERMA
C.E. Saclay
91191 GIF/YVETTE CEDEX
France
email: basile at soleil.saclay.cea.fr
More information about the Comp.sys.sun
mailing list