Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!bionet!agate!ucbvax!hplabs!pyramid!athertn!joshua From: joshua@athertn.Atherton.COM (Sleaze Hack) Newsgroups: comp.lang.c Subject: Re: variable number of strings passed to function - how? Message-ID: <234@olive.athertn.Atherton.COM> Date: 24 Oct 88 18:26:49 GMT References: <434@tutor.UUCP> <3533@ihuxz.ATT.COM> <1962@lznh.UUCP> Reply-To: joshua@atherton.com (Sleeze Hack) Organization: Atherton Technology, Sunnyvale, CA Lines: 35 In article <1962@lznh.UUCP> ariel@lznh.UUCP (<10000>Ariel Aloni) writes: > >[Lots deleted, but we're talking about the order arguments get pushed on > the stack during a C function call.] > >This is a convention adopted by most compilers, it was never promised >by K&R (maybe somebody can enlighten us on ANSI-C ?). > Not only does ANSI not promise us the order of arguments pushed on the stack, it does not promise us that this order will always be the same within a program! For example, the Tandem compiler (version C00 and later) pushes arguments left to right, unless the function takes a variable number of arguments, when it pushes them right to left. The standard says it is OK to force vararg functions to be prototyped before use, and Tandem requires this, so that it can always tell the difference between an "normal" function and a "vargargs" function. Obviously, having two different, and incompatible, stack frames in use in the same program can cause a lot of problems if you are not very careful. Think of all the problems that pointers to functions could cause! Tandem did this so that most function calls would be compatible with their other languages (PASCAL, TAL, etc.) which push arguments left to right. Tandem claims that this compiler is as ANSI conformant as possible (realizing that the standard is not a Standard yet). Summary on the portable use of variable arguments to a C function: use stdargs or varargs, or somewhere you will die. Josh -------- Quote: "If you haven't ported your program, it's not Addresses: a portable program. No exceptions." joshua@atherton.com OR sun!athertn!joshua OR {backbone}!{decwrl!hpda}!athertn!joshua work:(408)734-9822 home:(415)968-3718