From owner-freebsd-questions@FreeBSD.ORG Thu Dec 2 13:37:10 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D278C16A4CE for ; Thu, 2 Dec 2004 13:37:10 +0000 (GMT) Received: from mx.tele-kom.ru (mx.tele-kom.ru [213.80.148.6]) by mx1.FreeBSD.org (Postfix) with SMTP id 6A15143D2F for ; Thu, 2 Dec 2004 13:37:09 +0000 (GMT) (envelope-from doublef@tele-kom.ru) Received: (qmail 98290 invoked by uid 555); 2 Dec 2004 13:41:43 -0000 Received: from shark (213.80.149.245) by t-k.ru with TeleMail/2 id 1101994902-98070 for freebsd-questions@freebsd.org; Thu, Dec 2 16:41:42 2004 +0300 (MSK) Received: by shark (Postfix, from userid 1000) id C7267476; Thu, 2 Dec 2004 16:35:52 +0300 (MSK) Date: Thu, 2 Dec 2004 16:35:45 +0300 From: Sergey Zaharchenko To: Richard Tobin Message-ID: <20041202133541.GA26408@shark.localdomain> Mail-Followup-To: Sergey Zaharchenko , Richard Tobin , Andrea Venturoli , Rob , FreeBSD References: <20041202112724.657D21B43BB@macintosh.inf.ed.ac.uk> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="gBBFr7Ir9EOA20Yy" Content-Disposition: inline In-Reply-To: <20041202112724.657D21B43BB@macintosh.inf.ed.ac.uk> User-Agent: Mutt/1.4.2.1i X-Listening-To: /Machina_Vremeni/Beliy_den cc: Andrea Venturoli cc: Rob cc: FreeBSD Subject: Re: gcc violates const-ness of variable? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Dec 2004 13:37:10 -0000 --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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--