GCC Version: 4.2.3
Host: Ubuntu 8.04
When I compile the following code:
#include <stdio.h>
typedef struct person {
char name[40];
int age;
} Person;
static Person make_person(void);
int main(void) {
printf("%s\n", make_person().name);
return 0;
}
static Person make_person(void) {
static Person p = { "alexander", 18 };
return p;
}
I get a false warning:
warning: format %s expects type char *, but argument 2 has type char[40]
and when I execute the file I get a segmentation fault.
If I use: printf("%s\n", &make_person().name[0]);
everything works as expected and the output "alexander" is printed
--
Summary: Mistaken Segmentation fault
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: charpour at gnet dot gr
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755