Xref: utzoo comp.sys.mips:400 comp.sys.dec:2415 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!mips!gumby!lai From: lai@mips.COM (David Lai) Newsgroups: comp.sys.mips,comp.sys.dec Subject: Re: ANSI-C style variadic functions on MIPS Message-ID: <34218@mips.mips.COM> Date: 6 Jan 90 19:51:41 GMT References: <1990Jan5.085205.12473@athena.mit.edu> <15370@boulder.Colorado.EDU> <1990Jan6.062805.23863@athena.mit.edu> Sender: news@mips.COM Reply-To: lai@mips.COM (David Lai) Followup-To: comp.sys.mips Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 43 In article <1990Jan6.062805.23863@athena.mit.edu> raeburn@athena.mit.edu (Ken Raeburn) writes: > >Maybe I should point it out again: The troublesome case is a function >declared: > foo (double d, ...) > >How does it know, when you ask for a "double", that it should look at >the second FP reg save slot? All that's available to the macros is >the address of d; but since the macros can't tell the difference >between foo's declaration above and > foo2 (double d1, double d2, ...) >(for which it should start with the first stack argument) how does it >know when to switch from FP reg save slots to regular stack arguments? >It needs to know, if they aren't contiguous in memory. > >I should rephrase that: How _should_ it know? My claim is that >(lacking more information from the compiler) it does not. > >-- Ken The MIPS compiler does support full stdarg.h type calls, even if the first argument is a float (or double). The secret is that the prototype must be *visible* at the caller side (see ANSI section 4.8.1.3). The compiler knows where the beginning of the variable part of the argument list is (the position of the '...' in the prototype), and hence forces arguments to be passed in the integer registers (even arguments that are float or double). The actual function must also be *defined* with the same prototype form, including the '...'. Example: main() { extern foo(double,...); foo(2.0,3.0); /* passes 2.0 in fp reg, 3.0 in regular registers */ foo2(2.0,3.0); /* passes 2.0, 3.0 in fp regs */ } We are aware of limitations of the old style varargs.h type calls when the first argument is a float or double. -- "What is a DJ if he can't scratch?" - Uncle Jamms Army David Lai (lai@mips.com || {ames,prls,pyramid,decwrl}!mips!lai)