home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Portable Varargs?
- Message-ID: <1992Sep9.151730.27385@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Sep8.171222.20177@kpc.com>
- Date: Wed, 9 Sep 1992 15:17:30 GMT
- Lines: 42
-
- hollasch@kpc.com (Steve Hollasch) writes:
-
-
- > Is there a portable way to do variable argument functions that will
- >also work on ANSI C compilers as well as standard K&R C compilers? Right
- >now it looks like varargs.h and the accompanying macros works on the
- >platforms I've tried, but was wondering if I can assume that this utility
- >will work on all "reasonable" platforms.
-
- Variable-argument functions may be implemented in many different ways
- by compilers. For this reason, you can't rely on any particular
- set of macro definitions to be portable, by which I mean you can't
- carry around your own varargs.h or stdarg.h header file and expect
- it to work with an arbitrary C compiler.
-
- A C compiler will provide its own version of one or both of those header
- files which, one can only assume, will work correctly with the compiler.
- If you stick with use of the compiler-supplied header file and the
- usual macros, you should be all right.
-
- Unfortunately, the macros in varargs.h and stdarg.h are not compatible,
- and many compilers have one header but not the other. The method
- of declaring/defining a variable-arg function also depends on which
- set of macros you use, further complicating the issue.
-
- If you are lucky, all the compilers you need to use will support
- the Standard C <stdarg.h> and allow Standard C function prototypes.
- One hopes that more and more compilers, even if remaining backward-
- compatible, will support, or at least allow, Standard C features.
-
- Otherwise, you will have to use #ifdef's around function declarations,
- headers, and macro usage. This makes the code nearly unreadable.
- On the plus side, such functions tend to be rare, so you don't have
- to deal with this often.
-
- I don't recommend using varargs.h exclusively, since it will make
- porting the code to Standard C environments more difficult, and
- because varargs.h cannot be used with C++ at all.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-