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: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- Cc: dewar at adacore dot com (Robert Dewar), 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: 15 Jan 2006 18:22:25 -0600
- Subject: Re: Storage for uninitialized objects (PR 24626)
- References: <200601152113.k0FLDsmm002972@hiauly1.hia.nrc.ca>
"John David Anglin" <dave@hiauly1.hia.nrc.ca> writes:
| > > 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;
Where does the standard says that reading the value of an
unitialized object of character type is undefined behaviour?
My reading has always been that character types are exempted from that
black hole stuff.
-- Gaby