This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Storage for uninitialized objects (PR 24626)
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: dewar at adacore dot com (Robert Dewar)
- Cc: steven at gcc dot gnu dot org, gcc at gcc dot gnu dot org, schlie at comcast dot net, ian at airs dot com, jsm28 at gcc dot gnu dot org
- Date: Sun, 15 Jan 2006 16:13:54 -0500 (EST)
- Subject: Re: Storage for uninitialized objects (PR 24626)
> > This seems pretty clear. C99 requires that storage be allocated
> >
> >for uninitialized objects, that an indeterminate value be stored
> >in the object when the declarator for the object is reached in the
> >block, that the last-stored value be retained for the duration of
> >the block.
> >
> >
> I think that is an incorrect interpretation. Remember the standard is
> always "as-if" when it gives an implementation approach. Please
> show a correct C program that can tell that gcc is not following
> the above scheme.
#include <stdio.h>
unsigned char
T (unsigned char x)
{
static int first = 1;
static unsigned char firstx;
if (first)
{
first = 0;
firstx = x;
return ~x;
}
if (x == firstx)
printf ("Behavior is pre GCC 4.0\n");
else
printf ("Behavior is GCC 4.0 and later\n");
return 0;
}
*** cut ***
extern int T (unsigned char);
int
foo (void)
{
int result;
unsigned char x;
result = T (x);
T (x);
return result;
}
int
main ()
{
return foo ();
}
Compile as follows:
gcc-3.4 -O2 -c T.c
gcc-3.4 -o und -O2 und.c T.o
./und
Behavior is pre GCC 4.0
gcc-4.0 -o und -O2 und.c T.o
Behavior is GCC 4.0 and later
That's what I see on hppa-unknown-linux-gnu. The 4.0 behavior is
caused by GCC using result for the second call to T, whereas 3.3
and 3.4 use the same undefined value for both calls to T.
Dave
--
J. David Anglin dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6602)