This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A bug?
- From: Michel Van den Bergh <michel dot vandenbergh at uhasselt dot be>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 16 Dec 2008 17:05:08 +0100
- Subject: A bug?
Hi,
The following program segfaults when compiled with gcc
but runs fine when compiled with g++ or icc (the intel C compiler)
#include <stdio.h>
struct Hello {
char world[20];
};
struct Hello s(){
struct Hello r;
r.world[0]='H';
r.world[1]='\0';
return r;
}
int main(){
printf("%s\n",s().world);
}
Assigning s() to a variable and then using the variable avoids the
segfault.
gcc --version returns (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3).
Regards,
Michel