This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37755] New: Mistaken Segmentation fault
- From: "charpour at gnet dot gr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Oct 2008 21:15:03 -0000
- Subject: [Bug c/37755] New: Mistaken Segmentation fault
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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