two 'const' questions

Ciaran O'Riordan ciaran_o_riordan@hotmail.com
Mon Sep 9 02:44:00 GMT 2002


Hi all,
  I have two issues with the handling of 'const' variables.
I'm pretty sure they are implementation decisions but I
can't understand the reasoning.


#1 Why does GCC allow writing to 'const' globals and statics?

Since global and static variables are stored in the data
segment of an executable the program will always crash when
run.  A warning is given but I think it should be an error if
the code is a 100% certain bug.  Any ideas?


#2 Why doesn't GCC allow the use of 'const' variables as
   initialisation values?

When I have code declaring two globals like so:
const int cow = 6;
int moo = cow;
I get an error message saying "initialiser element is not
constant".  Why is this not allowed?  I haven't found anything
in the standard saying that const variables are not constants.

Any help/ideas/discussion on either of these would be appreciated.

Thanks
Ciaran O'Riordan


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx



More information about the Gcc-help mailing list