home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: inline and varargs clash???
- Message-ID: <1993Jan28.182155.27627@taumet.com>
- Organization: TauMetric Corporation
- References: <1993Jan28.014654.19611@wuecl.wustl.edu>
- Date: Thu, 28 Jan 1993 18:21:55 GMT
- Lines: 51
-
- pete@arl.wustl.edu (Peter Flugstad,,,) writes [abridged example]:
-
- >#include <stdio.h>
- >#include <stdarg.h>
-
- >inline void Debug_Sys_Print (char *format, ...)
- >{
- > va_list args;
- > va_start (args, format);
- > vprintf (format, args);
- > va_end (args);
- >}
-
- >main ()
- >{
- > Debug_Sys_Print ("Hello, %s\n", "World");
- > printf ("done...\n");
- >}
-
- >The problem I am having is that I get a linker error:
-
- >pete> CC -D_ERR_DEFINE -o print print.C
- >ld: Undefined symbol
- > __builtin_va_alist
-
- The variable-arg mechanism usually relies on arguments being passed
- in a certain way on the stack. An inline function usually doesn't
- pass arguments that way. (This is all extremely implementation-
- dependent.)
-
- If an implementation supports inlining of variable-arg functions, it
- must provide a set of macros in <stdarg.h> which will work with inline
- functions. Otherwise, it can simply generate variable-arg functions
- out-of-line. (A compiler is never obligated to generate an inline
- function in line.)
-
- It appears that this implementation attempts to inline the function
- but does not have a suitable <stdarg.h>. I have to consider this a bug.
- You are lucky in that the program failed to link, rather than simply
- crash or produce bogus answers.
-
- Fortunately, the workaround is simple. Don't declare variable-arg
- functions to be inline.
-
- If a function is heavily used and its calling sequence is comparable
- in size or speed to the body of the function, it is a good candidate
- for inlining. Otherwise, inlining may be counter-productive. It seems
- unlikely that a variable-arg function is a good candidate for inlining.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-