This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]