From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29015 invoked by alias); 30 Dec 2004 06:27:31 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 28850 invoked from network); 30 Dec 2004 06:27:23 -0000 Received: from unknown (HELO tce.edu) (203.129.194.19) by sourceware.org with SMTP; 30 Dec 2004 06:27:23 -0000 Received: from [10.0.0.2] (helo=proxy.tcenet) by tce.edu with esmtp (Exim 4.34) id 1Cjtmg-0002g1-DK; Thu, 30 Dec 2004 11:57:42 +0530 To: GCC Mailing list Subject: assigning to const int via pointer From: Joe Steeve X-GPG-Fingerprint: 8FF8 AC08 4EF7 03F3 71C0 A519 EAC7 6C39 2846 CFC6 X-GPG-Key: http://gnukid.shyper.com/key/js_public.key X-Operating-System: Debian GNU/Linux Organisation: Thiagarajar College of Engineering X-Home-Page: http://www.joesteeve.tk/ Date: Thu, 30 Dec 2004 06:27:00 -0000 Message-ID: <87652k5lcy.fsf@proxy.tcenet> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-SW-Source: 2004-12/txt/msg00259.txt.bz2 --=-=-= Content-length: 463 The following code assigns a value to a `const int` via a pointer., #include int main() { const int x=5; int *ptr; ptr = &x; *ptr = 10; printf("%d",x); } The code gives `10` for the following compilation $gcc -o test test.c It gives `5` when using optimisations switches., $gcc -o test -O2 test.c Feature or bug or any explanation for this? -- .O. A proud GNU user ..O http://www.joesteeve.tk/ OOO http://gnukid.5gigs.com/ --=-=-= Content-Type: application/pgp-signature Content-length: 188 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBB06WfKuw2FyFE6wcRAtpUAKDSXP3aC0cRnrooav7QLBeKheXxqACgtE+i FeN3uU8swAHxrDOa8PoL0jM= =wOpG -----END PGP SIGNATURE----- --=-=-=--