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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: inline and varargs clash???
  5. Message-ID: <1993Jan28.182155.27627@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1993Jan28.014654.19611@wuecl.wustl.edu>
  8. Date: Thu, 28 Jan 1993 18:21:55 GMT
  9. Lines: 51
  10.  
  11. pete@arl.wustl.edu (Peter Flugstad,,,) writes [abridged example]:
  12.  
  13. >#include <stdio.h>
  14. >#include <stdarg.h>
  15.  
  16. >inline void Debug_Sys_Print (char *format, ...)
  17. >{
  18. >  va_list args;
  19. >  va_start (args, format);
  20. >  vprintf (format, args);
  21. >  va_end (args);
  22. >}
  23.  
  24. >main ()
  25. >{
  26. >  Debug_Sys_Print ("Hello, %s\n", "World");
  27. >  printf ("done...\n");
  28. >}
  29.  
  30. >The problem I am having is that I get a linker error:
  31.  
  32. >pete> CC -D_ERR_DEFINE -o print print.C
  33. >ld: Undefined symbol 
  34. >   __builtin_va_alist 
  35.  
  36. The variable-arg mechanism usually relies on arguments being passed
  37. in a certain way on the stack.  An inline function usually doesn't
  38. pass arguments that way.  (This is all extremely implementation-
  39. dependent.)
  40.  
  41. If an implementation supports inlining of variable-arg functions, it
  42. must provide a set of macros in <stdarg.h> which will work with inline
  43. functions.  Otherwise, it can simply generate variable-arg functions
  44. out-of-line.  (A compiler is never obligated to generate an inline
  45. function in line.)
  46.  
  47. It appears that this implementation attempts to inline the function
  48. but does not have a suitable <stdarg.h>.  I have to consider this a bug.
  49. You are lucky in that the program failed to link, rather than simply
  50. crash or produce bogus answers.
  51.  
  52. Fortunately, the workaround is simple.  Don't declare variable-arg
  53. functions to be inline.
  54.  
  55. If a function is heavily used and its calling sequence is comparable
  56. in size or speed to the body of the function, it is a good candidate
  57. for inlining.  Otherwise, inlining may be counter-productive.  It seems
  58. unlikely that a variable-arg function is a good candidate for inlining.
  59. -- 
  60.  
  61. Steve Clamage, TauMetric Corp, steve@taumet.com
  62.