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: Is the GCC optimazer too smart?


2009/12/10 sergio borghese:
>
> Now my question is: is it correct that the compiler enforces the
> constantness of the variable, even tought it states in the warning
> that the const qualifier has been discarded?

the calls to printf can be optimised to printf("i: %dn", 0) so it
doesn't use the value of i, because the compiler knows that the value
of i cannot be changed by a valid program.  You didn't show what foo
does, but if you change the value of a const variable the program's
behaviour is undefined, so you can't rely on any particular behaviour.


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