Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Robert Paige Rendell
Mon, 27 Jul 1992 02:02
Bug report - GCC 2.2.2
Author: Robert Paige Rendell
Date: Mon, 27 Jul 1992 02:02
Date: Mon, 27 Jul 1992 02:02
74 lines
2171 bytes
2171 bytes
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~
/))\
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads