[Ilugc] Ansi C and 'const' modifier
- From: vijaykumar@xxxxxxxxxxxxx (Vijay Kumar Bagavath Singh)
- Date: Wed Aug 11 20:31:59 2004
From: Sridhar R <sridharinfinity@xxxxxxxxx>
const int a=10;
a=20;
when compiled with 'gcc' it gives only warning about modification of
const object. I think [1] according to ANSI Standard that should be
error.
Bug in gcc? or in my understanding?
Quoting from the ANSI C standard(8.2), "The purpose of const is to announce
objects that may be placed in read-only memory, and perhaps to increase
opportunities for optimization. ... Except that it should diagnose explicit
attempts to change const objects, a compiler may ignore these qualifiers."
BTW, if you compile the program with -O optimization flag, the value of `a'
will not change to 20.
Vijay
--
______________________________________________
Check out the latest SMS services @
http://www.linuxmail.org ;
This allows you to send and receive SMS through your mailbox.
Powered by Outblaze
Other related posts: