home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!gumby!wupost!eclnews!vader!pete
- From: pete@arl.wustl.edu (Peter Flugstad,,,)
- Subject: inline and varargs clash???
- Message-ID: <1993Jan28.014654.19611@wuecl.wustl.edu>
- Sender: usenet@wuecl.wustl.edu (News Administrator)
- Nntp-Posting-Host: vader
- Reply-To: pete@arl.wustl.edu
- Organization: Applied Research Lab, Washington University in St. Louis
- Date: Thu, 28 Jan 1993 01:46:54 GMT
- Lines: 90
-
- Hi, I'm trying to get the following code to compile on a Sun SPARC
- (Sun OS 4.1.3, Sun C++ 3.0.1, SC 2.0.1, cfront version 3.0.1).
-
- #include <stdio.h>
- #include <stdarg.h>
-
- #ifdef _ERR_DEBUG
- inline void Debug_Sys_Print (char *format, ...)
- {
- va_list args;
- va_start (args, format);
- vprintf (format, args);
- va_end (args);
- }
- #else _ERR_DEBUG
- inline void Debug_Sys_Print (char *format, ...)
- {
- }
- #endif _ERR_DEBUG
-
- main ()
- {
- Debug_Sys_Print ("Hello, %s\n", "World");
- printf ("done...\n");
- }
-
- The idea is that I want Debug_Sys_Print to be completely compiled out if
- _ERR_DEBUG is not defined... This is for performance reasons.
-
- (I know that wrapping an #ifdef-endif around the actual function call
- also works to remove the call, but this is a lot cleaner and easier to read)
-
- The problem I am having is that when I compile this normally with the
- _ERR_DEBUG defined I get a linker error:
-
- pete> CC -D_ERR_DEFINE -o print print.C
- ld: Undefined symbol
- __builtin_va_alist
-
- But when I compile with a +d (do not expand inlines), it works fine:
-
- pete> CC -D_ERR_DEFINE +d -o print print.C
- pete> ./print
- Hello, World
- done...
-
- This symbol "__builtin_va_alist" is from the <stdarg.h> file, here's the
- relavent portions of that file...
-
- #ifdef sparc
- # define va_alist __builtin_va_alist
- #endif
- ...
- #ifdef sparc
- extern char __builtin_va_alist;
- #define va_start(ap, parmN) ap = (char *)( &__builtin_va_alist )
- #else
- ...
-
- I have looked at the command line passed to ld, (via the -V command)
- and it's identical in both cases. If I look at the code cfront generates,
- of course has the function inlined in the first, and not in the second.
- (Despite this I could never find a reference to "__builtin_va_alist"
- in any of the libraries using nm).
-
- I guess the puzzling thing about this is why is ld complaining??? The only
- difference is that in one case Debug_Sys_Print is inline, and in the other,
- it's not. In both cases, __builtin_va_alist is defined as extern char (I
- looked at the code from cpp and cfront).
-
- I realize that for my purposes, adding the +d to the compile still does what
- I want. If ERR_DEFINE is not defined, (and also no +d) then the
- Debug_Sys_Print is empty, and cfront realizes that the inline function
- has no code, and so generates no code for it.
-
- I just guess it is a puzzle???
-
- Please e-mail me if you know why this is happening, as I don't generally read
- this news group. I'll summarize if there is enough interest.
-
- Thanx
-
- ---
- Pete Flugstad | Internet: pete@arl.wustl.edu
- Applied Research Laboratory | Tel: (314) 935-6110
- Department of Computer Science | "To err is Human, to really
- Washington University in St. Louis | foul up requires a computer"
-
-
-
-