varargs fails on typedefs

Brett Galloway brett at wjvax.UUCP
Wed Jul 30 10:49:34 AEST 1986


Doug Gwyn <seismo!BRL.ARPA!gwyn> sent me E-mail responding to my posting
about the need for a promote() operator to implement varargs.  Unforunately,
our mailer is broken, so I cannot respond privately.  In any event, I
believe that his response is of interest:

>This is the second such suggestion in recent weeks.
>I think we should be careful to distinguish between what the
>application code/programmer sees for an interface and
>what the C runtime implementer needs for his implementation.

><varargs.h> can be used safely if the programmer specifies
>the correct (possibly widened) type and if he restricts himself
>to the simpler data types.  X3J11 has designed <stdarg.h> to
>replace <varargs.h>, but there is still room for debate about
>the current design.

>Statements such as "<varargs.h> cannot be implemented without
>a promote() or alignof() operator" are simply false.  The
>existence of such operators would not even be sufficient for some
>architectures.  Rather than specify such fine-grained details
>of use only for implementing varargs, X3J11 is leaving it up
>to the implementor how he pulls this trick, and is specifying
>only the application code/programmer visible interface.  If
>this interface is properly designed, it will be implementable
>"somehow" on every significant architecture (although perhaps
>not purely in C).

As might be guessed, I disagree.  Of course, varargs can be implemented
without a promote() or alignof() operator; it is so implemented now.
However, it imposes the restrictions that Doug cites: "if the programmer
specifies the correct (possibly widened) type and if he restricts himself to
the simpler data types."

I argue that a promote() operator is necessary to remove these restrictions.
My article referred to using typedef'd types in varargs, and, in fact, without
a promote() operator, using typedef'd types in varargs is impossible.  Note
that promote() is a necessary condition; not a sufficient condition.

In short, I believe that X3J11, by omitting the (normally invisible) promote()
operator, is forcing itself to limit the usefulness of the (visible) stdarg
interface.

-- 
-------------
Brett Galloway
{pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett



More information about the Comp.lang.c mailing list