public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* assigning to const int via pointer
@ 2004-12-30  6:27 Joe Steeve
  2004-12-30  7:19 ` Sriharsha
  2004-12-30 16:02 ` Ian Lance Taylor
  0 siblings, 2 replies; 8+ messages in thread
From: Joe Steeve @ 2004-12-30  6:27 UTC (permalink / raw)
  To: GCC Mailing list

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]


The following code assigns a value to a `const int` via a
pointer.,

#include <stdio.h>

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/

[-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-01-03  6:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-30  6:27 assigning to const int via pointer Joe Steeve
2004-12-30  7:19 ` Sriharsha
2004-12-30 16:02 ` Ian Lance Taylor
2004-12-31  6:44   ` Sriharsha
2004-12-31 11:08     ` Gabriel Dos Reis
2004-12-31 14:52     ` Ian Lance Taylor
2005-01-03  6:57       ` Sriharsha
2004-12-31 21:43   ` Joe Steeve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).