home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!cis.ohio-state.edu!bruce.cs.monash.edu.au!rendell
- From: rendell@bruce.cs.monash.edu.au (Robert Paige Rendell)
- Subject: Bug report - GCC 2.2.2
- Message-ID: <9207271633.AA26291@geech.gnu.ai.mit.edu>
- Sender: gnulists@ai.mit.edu
- Organization: Gnus Not Usenet
- Distribution: gnu
- Date: Mon, 27 Jul 1992 08:33:08 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 78
-
- This is a bug report for gcc 2.2.2 to do with functions returning structures
- by value with vararg parameter lists.
-
- It seems that the vararg list gets corrupted if the function returns a
- structure (by value), but not if it returns a simple data type. This is a
- minimal program that demonstrated the bug on our system (DECstation5000
- running Ultrix 4.2)
- ================================================================================
- #include <stdio.h>
- #include <stdarg.h>
-
- struct spurious
- {
- int anumber;
- };
-
- int first(char *fmt, ...)
- {
- int pos, number;
- va_list args;
- int dummy;
-
- va_start(args, fmt);
- for (pos = 0; fmt[pos]; pos++)
- if (fmt[pos] == 'i')
- {
- number = va_arg(args, int);
- printf("%d", number);
- }
- else
- putchar(fmt[pos]);
- va_end(args);
- putchar('\n');
- return dummy;
- }
-
- struct spurious second(char *fmt, ...) /* same as 'first', except for the */
- { /* return type */
- int pos, number;
- va_list args;
- struct spurious dummy;
-
- va_start(args, fmt);
- for (pos = 0; fmt[pos]; pos++)
- if (fmt[pos] == 'i')
- {
- number = va_arg(args, int);
- printf("%d", number);
- }
- else
- putchar(fmt[pos]);
- va_end(args);
- putchar('\n');
- return dummy;
- }
-
- main()
- {
- first("hi there this works", 5, 20);
- second("hi there this works", 5, 20); /* no, it doesn't */
- }
- ================================================================================
- The output I got from this program was:
-
- h5 there th20s works
- h268435456 there th5s works
-
- Thanks for your time, and sorry if you're already aware of this bug.
-
- Have fun,
- Rob R.
- \((/
- ~oo~
- /))\
-
-
-
-
-