Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.c Subject: Re: Variable Parameters Summary: Variable Arguments + Structure Assignment Message-ID: <631@s5.Morgan.COM> Date: 31 Dec 89 08:07:30 GMT References: <1169@zip.eecs.umich.edu> <1989Dec31.013746.2349@utzoo.uucp> Organization: Morgan Stanley & Co. NY, NY Lines: 43 I need to make assignment of any number of variables of any type to a temporary stack, and then reassign them back again. I'm at present using two versions (one with varargs.h for System V and one with stdarg.h for ANSI C). I pass the 'return addresses' and sizes of the variables, a single punctuational NULL, and then the list of values as function arguments. I then memcpy the appropriate sizes for the values (indexed just after the NULL marker argument) into the waiting addresses. This (for those who may be interested in speed) is not too slow - on a CISC architecture like the 386 it's only about 2.5 times as much time as the equivalent structure assignment, (which can't be coded because the arguments are not always of some given type), but on a RISC (like a Sun 4) it's about 20 times as slow. (Gack!). Now this business is not without at least one fine point I can't really get around; and that is the size of a variable is not always the same as it's size as an argument passed to a function on a stack. The complicated part (aside from the instant Hell of memory model complications) seems to come when using type char data which gets widened to int. It seems that where your character ends up in the int cannot be known without knowledge of the dreaded byte-ordering of the machine. Also; since there is no way to know at run-time what type the argument has, sizeof isn't so helpful on the way into this function. Essentially, I'm trying to write a 'remember' function which retains the values of any collection of assignable l-values for future re-assignment. The function is of type void, but could be assumed to be called 'recursively' in the sense that evaluation of the r-values may call functions which call 'remember'. Has anyone got a standard or portable way to do this? P.S. Is there some strange side effect of going from System V style varargs to ANSI stdarg which changes the code generation between caller and called? The profile timings of the two otherwise identical versions of a function using 'remember' compiled on the SCO / Microsoft UNIX System V/386 r3.2 C compiler differ in how the time is split between the caller and the called routine. The ANSI version has a faster called routine, but the System V UNIX-style version makes up the difference (nearly exactly) by having a faster caller. Is this due to the dPANS? Thanks in Advance, Andrew Mullhaupt