Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!mcsun!ukc!warwick!steve From: steve@maths.warwick.ac.uk (Steve Rumsby) Newsgroups: comp.lang.c++ Subject: Re: stdarg on sparc Message-ID: <2030@diamond.warwick.ac.uk> Date: 12 Dec 89 16:33:42 GMT Sender: news@warwick.ac.uk Reply-To: steve@maths.warwick.ac.uk (Steve Rumsby) Organization: Mathematics Institute, University of Warwick, UK. Lines: 91 Yes, it's possible to make it work. There are two things you need to do, one to the code itself, and one to the CC script (or to the output of CC -Fc before feeding to cc itself if you can't hack CC). 1) To the code using stdargs: First, add this to the beginning, or in a header file that you include, or somewhere: #ifdef sparc #define SA(x) __builtin_va_alist #else #define SA(x) x #endif Then change code like this: void foo(int x, char *p, ...) { va_list ap; if(!p) return; va_start(ap, p); [...etc...] } To this: void foo(int x, char *SA(p), ...) { va_list ap; if(!SA(p)) return; va_start(ap, SA(p)); [...etc...] } ie. change ALL occurances of the last named argument to SA(name). 2) Changes to CC itself: Cfront in going to mangle the __builtin_va_alist parameter name, so we need to unmangle it again so that the C compiler gets to see it. Do this to the output of cfront: sed -e 's/__0__builtin_va_alist/__builtin_va_alist/g' You can either do this in the CC script by changing all occurances of "cfront" to "cfront | sed", or you can do it to the output of CC -Fc and feed it to cc manually. This sed script can obviously be generalised to unmangle a larger set of identifiers (like all __builtin ones) if necessary (eg. to use gcc instead of cc as the C compiler). Voila! You now have stdargs working on a sparc machine. Note that there is a slightly more complex usage of stdargs in C++ which breaks the above system. This is where arguments after the last named one have default values, like so: extern void foo(int, char *, int = 2, ...); void foo(int x, char *p, int, ...) { va_list ap; va_start(ap, p); } [Is this legal? I found it in ET++] Cfront will make up names for the unnamed arguments, and the Sun C compiler complains about arguments after __builtin_va_alist. To make this work you need to rip out these extra arguments (I don't understand why cfront puts them there in the first place, actually). This is somewhat more difficult, but not impossible. I haven't got around to fixing this yet... Hope all this helps, Steve. UUCP: ...!ukc!warwick!steve Internet: steve@maths.warwick.ac.uk JANET: steve@uk.ac.warwick.maths PHONE: +44 203 523523 x2657