Reality check (Was Re: prototypes required ?)

Michael Meissner meissner at osf.org
Tue Oct 23 03:59:44 AEST 1990


In article <14199 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn)
writes:

| In article <1171 at dms.UUCP> albaugh at dms.UUCP (Mike Albaugh) writes:
| >	And neither will vast quantities of old code, which are used to
| >"rolling their own" varargs routines.
| 
| That never was a very wise practice, and <varargs.h> was devised LONG AGO
| to provide portable support for such situations.  I lost track of how
| many thousands of lines of other people's source code I have had to
| change to use <varargs.h> when porting to an environment different from
| the model that they assumed when they "rolled their own" variable-
| argument code.
| 
| I expect most conforming implementations to also provide <varargs.h> as
| a convenience for their customers, although some may well require the
| extra hooks that the standard provides and thus really not be able to
| implement <varargs.h>, only <stdarg.h>.

With the MIPS standard calling sequence (also used in DECstations, and
Silicon Graphics systems), there is one case that is impossible with
varargs, but can be handled with stdarg.  If the first argument is
floating point, the MIPS calling sequence passes the number in a
floating point register, otherwise it passes the first argument in
integer registers.  If the second argument was floating point and the
first one was as well, it too is passed in a floating point register,
otherwise it is passed in an integer register.  The varargs stuff only
works for arguments passed in integer registers.  Because varargs
functions don't tell the compiler anything in terms of a prototype,
the compiler doesn't have a clue that it should really pass the
floating point arguments in an integer register.

The one thing that varargs can do which stdarg can't, is vary the type
of the first parameter, since stdarg requires at least one
non-varardic argument to hook into.  In the ANSI meetings this was
brought up and dismissed due to thinking the case was artifical, and
that no real code actually dependend on it.  Well we just found that
one OS test suite does in fact depend on this, and only passes one
argument to a varardic function, using other means to tell what type
the argument is.  In a similar vein, you can't have a stdarg function
which takes zero or more arguments....


--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?



More information about the Comp.std.c mailing list