   A C90 Standards Idiom
  I was using gcc compiling a small CPP program earlier today and noticed something about the standard that i couldn't understand.I had some code like this:/* headers */const unsigned int secondsInHour = 3600;const unsigned int secondsInDay  = secondsInHour * 24;/* rest of code */Now i got errors that were basically saying that i was trying to assign a non-const value to a const object. Now since everything in the above statements are const, how is this so.There is no way that anything there can change at run-time.Can anyone shed some light on this?Dave   
  They are still, technically, run-time constants however. C++ suffers from many of the same issues when other types are involved.Note that unlike C++ such constants are not implicitly static.Try using an enum of define constant instead.   ;  You code prefectly compiled under VS.NET, is there any chance you're using older GCC version ?   ;  no, it does not compile in VS2003, it gives: "error C2099: initializer is not a constant"Dave wrote about C90, so this is C code and not C++ codeas C++ code it compile in VS2003;  I can't justify why this is not allowed in C90.   ;Quote:Original post by DaveI can't justify why this is not allowed in C90.Even though it's practically a constant the language still doesn't treat it as such. There are many other examples too, "a"[0] isn't a constant expression for instance.Try compiling the following in C++:const double foo = 1.0;enum { bar = foo };Note that this isn't really a pratical problem for integer constants since you've got enum's for those anyway.   ;  Well there is absolutely no chance of it being changed, but it is silly.This also is not allowed:const int compareRhs = 10;switch ( someVariable ){  case compareRhs:  {    break;  }}Dave   ;Original post by DaveI was using gcc compiling a small CPP program earlier today and noticed something about the standard that i couldn't understand.I had some code like this:/* headers */const unsigned int secondsInHour = 3600;const unsigned int secondsInDay  = secondsInHour * 24;/* rest of code */Compiles without error on Dev C++ 4.9.9.2;Quote:Original post by Anonymous PosterQuote:Original post by DaveI was using gcc compiling a small CPP program earlier today and noticed something about the standard that i couldn't understand.I had some code like this:/* headers */const unsigned int secondsInHour = 3600;const unsigned int secondsInDay  = secondsInHour * 24;/* rest of code */Compiles without error on Dev C++ 4.9.9.2Under gcc it doesn't compile. gcc is more standards complient than most. Also you *may* be using DevC++ and compiling with it in C++ not C.Dave   ;Quote:Original post by Dave/* headers */const unsigned int secondsInHour = 3600;const unsigned int secondsInDay  = secondsInHour * 24;/* rest of code */It's legal C++ but not legal C89.