This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Really, really const


Steven Bosscher <s.bosscher@student.tudelft.nl> writes:

| Op vr 26-09-2003, om 09:59 schreef Andrew Haley:
| >  > | The memory a[0] is read twice.  Is there any attrribute I can use to
| >  > | stop gcc from doing this?
| >  > 
| >  > GCC should be able to get that right without resorting to attributte
| >  > hackery. 
| > 
| > I think the C standard says that gcc has to read the memory twice.
| > 
| > Just because that memory is declared const here that doesn't mean that
| > it is const everywhere else; it just means that it's read-only here.
| > It might change.
| 
| If you are right, then GCC is buggy.

I don't think he is right.  More specifically, any attempt to modify an
object defined with a const qualification is undefined behaviour.
Quoting the C standard,

6.7.3

       [#5] If an attempt is made to modify an object defined  with
       a  const-qualified  type  through use of an lvalue with non-
       const-qualified type, the  behavior  is  undefined.   If  an
       attempt  is  made  to  refer  to  an  object  defined with a
       volatile-qualified type through use of an lvalue  with  non-
       volatile-qualified type, the behavior is undefined.113)
 

Therefore, I think GCC-3.2.2 is right in the code it produces.  
a[0] is really, really const.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]