home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 2016 < prev    next >
Encoding:
Text File  |  1992-07-29  |  3.9 KB  |  177 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!convex.com!graham
  3. From: graham@convex.com (Marv Graham)
  4. Subject: 2.2.2 stdio.h <=> stdarg.h problem
  5. Message-ID: <1992Jul29.164845.256@news.eng.convex.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Engineering, CONVEX Computer Corp., Richardson, Tx., USA
  8. Distribution: gnu
  9. Date: Wed, 29 Jul 1992 16:48:45 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 164
  12.  
  13. On OSF i386 systems, the standard /usr/include/stdio.h contains the lines
  14.  
  15. /*
  16.  * (c) Copyright 1990, 1991, OPEN SOFTWARE FOUNDATION, INC.
  17.  * ALL RIGHTS RESERVED
  18.  */
  19. /*
  20.  * OSF/1 Release 1.0.1
  21.  */
  22. /* @(#)$RCSfile: stdio.h,v $ $Revision: 2.11.4.3 $ (OSF) $Date: 91/03/11 15:02:20 $ */
  23. /*
  24.  * COMPONENT_NAME: stdio.h
  25.  *                                                                    
  26.  * ORIGIN: IBM
  27.  *
  28.  * Copyright International Business Machines Corp. 1985, 1988
  29.  * All Rights Reserved
  30.  * Licensed Material - Property of IBM
  31.     ...
  32.     ...
  33.     ...
  34. #ifndef _VA_LIST
  35. #define _VA_LIST
  36. typedef char * __va_list;
  37. extern int  vfprintf(FILE *, const char *, __va_list );
  38. extern int  vprintf(const char *, __va_list );
  39. extern int  vsprintf(char *, const char *, __va_list );
  40. #else
  41. extern int  vfprintf(FILE *, const char *, va_list );
  42. extern int  vprintf(const char *, va_list );
  43. extern int  vsprintf(char *, const char *, va_list );
  44. #endif
  45.     ...
  46.     ...
  47.     ...
  48.  
  49. ###############################################################################
  50.  
  51. The GNU file gstdarg.h which eventaully becomes
  52.     /usr/local/lib/gcc-lib/.../include/stdarg.h
  53. contains the lines
  54.  
  55. /* stdarg.h for GNU.
  56.    Note that the type used in va_arg is supposed to match the
  57.    actual type **after default promotions**.
  58.    Thus, va_arg (..., short) is not valid.  */
  59.  
  60. #ifndef _STDARG_H
  61. #define _STDARG_H
  62.     ...
  63.     ...
  64.     ...
  65. #ifdef _HIDDEN_VA_LIST  /* On OSF1, this means varargs.h is "half-loaded".  */
  66. #undef _VA_LIST
  67. #endif
  68.  
  69. /* The macro _VA_LIST_ is the same thing used by this file in Ultrix.  */
  70. #ifndef _VA_LIST_
  71. /* The macro _VA_LIST is used in SCO Unix 3.2.  */
  72. #ifndef _VA_LIST
  73. #define _VA_LIST_
  74. #define _VA_LIST
  75. #ifndef __svr4__
  76. typedef char *va_list;
  77. #else
  78. typedef void *va_list;
  79. #endif
  80. #endif /* _VA_LIST */
  81. #endif /* _VA_LIST_ */
  82.     ...
  83.     ...
  84.     ...
  85.  
  86. Since <stdio.h> does not mention _HIDDEN_VA_LIST, a source program that begins
  87. with
  88.  
  89. #include    <stdio.h>
  90. #include    <stdarg.h>
  91.  
  92. leaves "va_list" undefined.
  93.  
  94. The sequence
  95.  
  96. #include    <stdarg.h>
  97. #include    <stdio.h>
  98.  
  99. defines "va_list".
  100.  
  101. If /usr/include/stdarg.h is used explicitly,
  102.     #include    "/usr/include/stdarg.h"
  103. there is no problem in either case.
  104.  
  105. ###############################################################################
  106.  
  107. The complete program (modified in the #inlcude lines only) that led to this
  108. report is
  109.  
  110. #ifdef FIRST
  111. #include <stdio.h>
  112. #include "/usr/include/stdarg.h"
  113. #else    /* FIRST */
  114. #include "/usr/include/stdarg.h"
  115. #include <stdio.h>
  116. #endif    /* FIRST */
  117.  
  118. struct spurious
  119. {
  120.     int anumber;
  121. };
  122.  
  123. int first(char *fmt, ...)
  124. {
  125.     int pos, number;
  126.     va_list args;
  127.     int dummy;
  128.  
  129.     va_start(args, fmt);
  130.     for (pos = 0; fmt[pos]; pos++)
  131.     if (fmt[pos] == 'i')
  132.     {
  133.         number = va_arg(args, int);
  134.         printf("%d", number);
  135.     }
  136.     else
  137.         putchar(fmt[pos]);
  138.     va_end(args);
  139.     putchar('\n');
  140.     return dummy;
  141. }
  142.  
  143. struct spurious second(char *fmt, ...)    /* same as 'first', except for the */
  144. {                    /* return type */
  145.     int pos, number;
  146.     va_list args;
  147.     struct spurious dummy;
  148.  
  149.     va_start(args, fmt);
  150.     for (pos = 0; fmt[pos]; pos++)
  151.     if (fmt[pos] == 'i')
  152.     {
  153.         number = va_arg(args, int);
  154.         printf("%d", number);
  155.     }
  156.     else
  157.         putchar(fmt[pos]);
  158.     va_end(args);
  159.     putchar('\n');
  160.     return dummy;
  161. }
  162.  
  163. main()
  164. {
  165.     first("hi there this works", 5, 20);
  166.     second("hi there this works", 5, 20); /* no, it doesn't */
  167. }
  168.  
  169.  
  170. This program works when FIRST is either defined or not defined on the gcc
  171. command line.
  172.  
  173.  
  174. Marv Graham; Convex Computer Corp.  {uunet,sun,uiucdcs,allegra}!convex!graham
  175.                     graham@bach.convex.com
  176.  
  177.