This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: An Ansi-C question or... Is egcs/gcc Ansi compliant?



> Just playing with const:
> 
> const int i=3D0;
>    i++;
>    printf("%i\n",i);
> 
> You get a warning only (increment of read-only variable) and then both =
> compiles
> (egcs&gcc) and 'i' is modified at runtime. I was perplexed and checked =
> this with
> other compilers (OSF's, vc++, bcb) and couldn't even compile this.

egcs is technically correct, in that all that the ANSI/ISO standard
requires is a diagnostic here, and a warning qualifies as a diagnostic.

However, I agree with you that const violations of this kind should
be errors, not warnings ... especially if egcs then goes on to put i
in a read-only section and the program crashes at runtime!

> Why ignore egcs/gcc the const keyword such way?

The keyword is not ignored, you get a warning.

> Is there anyway to get a real const with egcs?

It's a real const.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]