Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Dec 2004 16:35:45 +0300
From:      Sergey Zaharchenko <doublef@tele-kom.ru>
To:        Richard Tobin <richard@inf.ed.ac.uk>
Cc:        FreeBSD <freebsd-questions@freebsd.org>
Subject:   Re: gcc violates const-ness of variable?
Message-ID:  <20041202133541.GA26408@shark.localdomain>
In-Reply-To: <20041202112724.657D21B43BB@macintosh.inf.ed.ac.uk>
References:  <20041202112724.657D21B43BB@macintosh.inf.ed.ac.uk>

next in thread | previous in thread | raw e-mail | index | archive | help

--gBBFr7Ir9EOA20Yy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

<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...
>=20
> 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.
>=20
> 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,

--=20
DoubleF
A LISP programmer knows the value of everything, but the cost of
nothing.

--gBBFr7Ir9EOA20Yy
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFBrxohwo7hT/9lVdwRAoDbAJ9PchrgX6fUT7kyTiBg26A2oQlflwCffLaE
CeLVJ8fuD/j9ZAPC6RSooN0=
=/JZu
-----END PGP SIGNATURE-----

--gBBFr7Ir9EOA20Yy--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041202133541.GA26408>