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

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!bruce.cs.monash.edu.au!rendell
  3. From: rendell@bruce.cs.monash.edu.au (Robert Paige Rendell)
  4. Subject: Bug report - GCC 2.2.2
  5. Message-ID: <9207271633.AA26291@geech.gnu.ai.mit.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Gnus Not Usenet
  8. Distribution: gnu
  9. Date: Mon, 27 Jul 1992 08:33:08 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 78
  12.  
  13. This is a bug report for gcc 2.2.2 to do with functions returning structures
  14. by value with vararg parameter lists.
  15.  
  16. It seems that the vararg list gets corrupted if the function returns a
  17. structure (by value), but not if it returns a simple data type.  This is a
  18. minimal program that demonstrated the bug on our system (DECstation5000
  19. running Ultrix 4.2)
  20. ================================================================================
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23.  
  24. struct spurious
  25. {
  26.     int anumber;
  27. };
  28.  
  29. int first(char *fmt, ...)
  30. {
  31.     int pos, number;
  32.     va_list args;
  33.     int dummy;
  34.  
  35.     va_start(args, fmt);
  36.     for (pos = 0; fmt[pos]; pos++)
  37.     if (fmt[pos] == 'i')
  38.     {
  39.         number = va_arg(args, int);
  40.         printf("%d", number);
  41.     }
  42.     else
  43.         putchar(fmt[pos]);
  44.     va_end(args);
  45.     putchar('\n');
  46.     return dummy;
  47. }
  48.  
  49. struct spurious second(char *fmt, ...)    /* same as 'first', except for the */
  50. {                    /* return type */
  51.     int pos, number;
  52.     va_list args;
  53.     struct spurious dummy;
  54.  
  55.     va_start(args, fmt);
  56.     for (pos = 0; fmt[pos]; pos++)
  57.     if (fmt[pos] == 'i')
  58.     {
  59.         number = va_arg(args, int);
  60.         printf("%d", number);
  61.     }
  62.     else
  63.         putchar(fmt[pos]);
  64.     va_end(args);
  65.     putchar('\n');
  66.     return dummy;
  67. }
  68.  
  69. main()
  70. {
  71.     first("hi there this works", 5, 20);
  72.     second("hi there this works", 5, 20); /* no, it doesn't */
  73. }
  74. ================================================================================
  75. The output I got from this program was:
  76.  
  77. h5 there th20s works
  78. h268435456 there th5s works
  79.  
  80. Thanks for your time, and sorry if you're already aware of this bug.
  81.  
  82.                                 Have fun,
  83.                                   Rob R.
  84.                                   \((/
  85.                                   ~oo~
  86.                                   /))\
  87.  
  88.  
  89.  
  90.  
  91.