This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC - Preserving statement expression results on stack
- From: Joe Perches <joe at perches dot com>
- To: Andrew Haley <aph-gcc at littlepinkcloud dot COM>
- Cc: gcc-help at gcc dot gnu dot org, Eric Botcazou <ebotcazou at libertysurf dot fr>
- Date: Thu, 30 Aug 2007 08:07:21 -0700
- Subject: Re: GCC - Preserving statement expression results on stack
- References: <1188426212.6062.101.camel@localhost> <18134.36449.770600.205122@zebedee.pink>
On Thu, 2007-08-30 at 10:31 +0100, Andrew Haley wrote:
> Joe Perches writes:
> > I know that gcc preserves stack slots for statement expressions.
> > http://gcc.gnu.org/ml/gcc-patches/2002-02/msg00958.html
> > What about statement expressions that return arrays?
> > When does GCC free stack used by statement expression array returns?
> > For instance:
> > #define itoa(i) \
> > ({ char tmp[16]; sprintf(tmp, "%d", i); tmp; })
> > printf("%s %s\n", itoa(1), itoa(2));
> > is the printf output guaranteed to be "1 2" or is it undefined?
>
> ISO/IEC 9899:1999 (E)
>
> 6.2.1 Scopes of identifiers
>
> 2 For each different entity that an identifier designates, the
> identifier is visible (i.e., can be used) only within a region of
> program text called its scope.
>
> Unless you see some gcc documentation to the contary, that's the rule.
Statement expressions are gcc extensions, ISO scoping rules
don't necessarily apply.
Is this guaranteed?
#define SE_identity(i) ({ typeof (i) x = i; x;})
printf("%d %d\n", SE_identity(1), SE_Identity(2));
Output: "1 2"