gcc violates const-ness of variable?
Sergey Zaharchenko
doublef at tele-kom.ru
Thu Dec 2 05:37:10 PST 2004
<Figured Rob would never get an off-list reply because of an invalid
address... sending the reply here>
On Thu, Dec 02, 2004 at 11:27:24AM +0000,
Richard Tobin probably wrote:
> > IIRC "const" does not exist in *standardized* C...
>
> No, it exists in both C89 and C99. But the error is in your program,
> not the compiler. "const" in C is a promise that you do not change
> the value, and you break that promise.
>
> It may be different in C++, I don't know.
In C, your promise is a promise to yourself only. In C++, the compiler
believes your promise and optimizes out the variable so that
printf(...,n) becomes printf(...,0). C++ is intendedly so `gullible' to
make more aggressive optimizations (like this) possible.
Try turning off optimizations for g++ to see if that `helps', but the
code is not valid C++ anyway.
HTH,
--
DoubleF
A LISP programmer knows the value of everything, but the cost of
nothing.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20041202/9c2102a3/attachment.bin
More information about the freebsd-questions
mailing list