------- Additional Comments From austern at apple dot com  2004-12-03 18:59 
-------
Subject: Re:  Incorrect reinitialization of compound literal

On Dec 3, 2004, at 10:50 AM, pinskia at gcc dot gnu dot org wrote:

>
> ------- Additional Comments From pinskia at gcc dot gnu dot org  
> 2004-12-03 18:50 -------
> But reading 6.5.2.5 P 16 seems to say something different.
>
> What it seems to say is:
>   p = &((int) {1});
> is to set the int to be one and then take the address.  We still point 
> to the same int as before.

Not exactly.  We still point to the same (one-element) array of ints we 
did before.  The array is modifiable, and we're changing the value of 
the first element in the array.  You might think that we should be 
reinitializing the object, but that's wrong.  When we execute that 
statement a second time all we're doing is setting p to the address of 
the compound literal again, but we have change the value of that 
compound literal.

It may sound odd to say that we're changing the value of a literal, but 
C compound literals really are odd.  6.5.2.5 is quite explicit that 
compound literals with modifiable types are modifiable.

The example in 6.5.2.5/16 is testing something completely different.  
It checks to make sure that we're only creating the object once.  My 
test case checks for that (yes, we get that right; we only create the 
object once) and also checks to make sure that changes in the object 
are reflected correctly.



-- 


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

Reply via email to