------- Comment #3 from joseph at codesourcery dot com  2008-10-06 21:39 -------
Subject: Re:   New: Mistaken Segmentation fault

On Mon, 6 Oct 2008, charpour at gnet dot gr wrote:

>   printf("%s\n", make_person().name);

make_person().name is a non-lvalue array, so it only decays to a pointer 
for C99, not for C90.  If you use -std=c99/-std=gnu99 then the program 
works.

The program does not, however, have defined behavior for C99, only for 
C1x.  In C99 the lifetime of the array ends at the next sequence point, 
before the call to printf.  In C1x it instead ends at the end of the 
evaluation of the containing full expression, which is the call to printf.

I do not believe any changes to GCC are needed to implement this 
particular C1x requirement, since GCC discards information about variables 
lifetimes smaller than a function for gimplification and tree 
optimizations that may change those lifetimes, so it will in practice 
treat the lifetime as being anywhere it cannot show the temporary not to 
be live.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37755

Reply via email to