home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19941 < prev    next >
Encoding:
Text File  |  1993-01-27  |  3.1 KB  |  103 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gumby!wupost!eclnews!vader!pete
  3. From: pete@arl.wustl.edu (Peter Flugstad,,,)
  4. Subject: inline and varargs clash???
  5. Message-ID: <1993Jan28.014654.19611@wuecl.wustl.edu>
  6. Sender: usenet@wuecl.wustl.edu (News Administrator)
  7. Nntp-Posting-Host: vader
  8. Reply-To: pete@arl.wustl.edu
  9. Organization: Applied Research Lab, Washington University in St. Louis
  10. Date: Thu, 28 Jan 1993 01:46:54 GMT
  11. Lines: 90
  12.  
  13. Hi, I'm trying to get the following code to compile on a Sun SPARC
  14. (Sun OS 4.1.3, Sun C++ 3.0.1, SC 2.0.1, cfront version 3.0.1).
  15.  
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18.  
  19. #ifdef _ERR_DEBUG
  20. inline void Debug_Sys_Print (char *format, ...)
  21. {
  22.   va_list args;
  23.   va_start (args, format);
  24.   vprintf (format, args);
  25.   va_end (args);
  26. }
  27. #else  _ERR_DEBUG
  28. inline void Debug_Sys_Print (char *format, ...)
  29. {
  30. }
  31. #endif _ERR_DEBUG
  32.  
  33. main ()
  34. {
  35.   Debug_Sys_Print ("Hello, %s\n", "World");
  36.   printf ("done...\n");
  37. }
  38.  
  39. The idea is that I want Debug_Sys_Print to be completely compiled out if 
  40. _ERR_DEBUG is not defined...  This is for performance reasons.  
  41.  
  42. (I know that wrapping an #ifdef-endif around the actual function call
  43. also works to remove the call, but this is a lot cleaner and easier to read)
  44.  
  45. The problem I am having is that when I  compile this normally  with the
  46.  _ERR_DEBUG defined I get a linker error:
  47.  
  48. pete> CC -D_ERR_DEFINE -o print print.C
  49. ld: Undefined symbol 
  50.    __builtin_va_alist 
  51.  
  52. But when I compile with a +d (do not expand inlines), it works fine:
  53.  
  54. pete> CC -D_ERR_DEFINE +d -o print print.C
  55. pete> ./print
  56. Hello, World
  57. done...
  58.  
  59. This symbol "__builtin_va_alist" is from the <stdarg.h> file, here's the 
  60. relavent portions of that file...
  61.  
  62. #ifdef sparc
  63. #   define va_alist __builtin_va_alist
  64. #endif
  65. ...
  66. #ifdef sparc
  67. extern char __builtin_va_alist;
  68. #define va_start(ap, parmN) ap = (char *)( &__builtin_va_alist )
  69. #else
  70. ...
  71.  
  72. I have looked at the command line passed to ld, (via the -V command)
  73. and it's identical in both cases.  If I look at the code cfront generates, 
  74. of course has the function inlined in the first, and not in the second. 
  75. (Despite this I could never find a reference to "__builtin_va_alist"
  76. in any of the libraries using nm).
  77.  
  78. I guess the puzzling thing about this is why is ld complaining???   The only
  79. difference is that in one case Debug_Sys_Print is inline, and in the other,
  80. it's not.  In both cases, __builtin_va_alist is defined as extern char (I 
  81. looked at the code from cpp and cfront).
  82.  
  83. I realize that for my purposes, adding the +d to the compile still does what 
  84. I want.  If ERR_DEFINE is not defined, (and also no +d) then the 
  85. Debug_Sys_Print is empty,  and cfront realizes that the inline function
  86. has no code, and so generates no code for it.  
  87.  
  88. I just guess it is a puzzle???
  89.  
  90. Please e-mail me if you know why this is happening, as I don't generally read 
  91. this news group. I'll summarize if there is enough interest.
  92.  
  93. Thanx
  94.  
  95. ---
  96. Pete Flugstad                | Internet: pete@arl.wustl.edu
  97. Applied Research Laboratory        | Tel: (314) 935-6110
  98. Department of Computer Science        | "To err is Human, to really 
  99. Washington University in St. Louis    |  foul up requires a computer"
  100.  
  101.  
  102.  
  103.