Path: utzoo!attcan!uunet!lll-winken!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: passing variable numbers of arguments Message-ID: <9358@smoke.BRL.MIL> Date: 13 Jan 89 05:56:12 GMT References: <899@thor.stolaf.edu> <15341@mimsy.UUCP> <449@marob.MASA.COM> <9317@smoke.BRL.MIL> <11378@haddock.ima.isc.com> <9321@smoke.BRL.MIL> <11410@haddock.ima.isc.com> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: na Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <11410@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes: >... given this information, the code ... is portable. No it isn't!! Apart from the obvious slip of picking up an int where a long was required (which can be fixed), your use of sizeof to adjust the byte count is flawed, because sizeof doesn't take into account alignment requirements of the arguments, which can (and sometimes do) differ from those of array members. To make this work portably, you would have to require implementations to provide at least one more va_ function, but what's the point? By that time, the postulated utility of an argument byte count has been lost under a barrage of details. By the way, the alternate idea of casting argument addresses to (char *) then subtracting them to count bytes fails due to not knowing in advance what the type of the next argument is. There may be room for another argument of one type, but not of another type, and unless you know more than byte counts you cannot determine whether or not to pick up another argument.