public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* An Ansi-C question or... Is egcs/gcc Ansi compliant?
@ 1998-12-30  2:25 Enrique I.R.
  1998-12-30 19:37 ` Joe Buck
  1998-12-31  2:22 ` Martin v. Loewis
  0 siblings, 2 replies; 3+ messages in thread
From: Enrique I.R. @ 1998-12-30  2:25 UTC (permalink / raw)
  To: egcs mailing list

Hi.

Just playing with const:

const int i=0;
   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.

Why ignore egcs/gcc the const keyword such way?
Is there anyway to get a real const with egcs?

PS: I don't know this message is really on-topic here. If you know of a mailing
list this could fit better, please tell me.

(for USENET postings) Delete 'CUTTHIS' from my e-mail to reply.
        -----------
        Enrique I.R.
 Freelance Sofware Developer.
   Gran Canaria. Spain.
  --aka CtrInt on #Linux--

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

* Re: An Ansi-C question or... Is egcs/gcc Ansi compliant?
  1998-12-30  2:25 An Ansi-C question or... Is egcs/gcc Ansi compliant? Enrique I.R.
@ 1998-12-30 19:37 ` Joe Buck
  1998-12-31  2:22 ` Martin v. Loewis
  1 sibling, 0 replies; 3+ messages in thread
From: Joe Buck @ 1998-12-30 19:37 UTC (permalink / raw)
  To: Enrique I.R.; +Cc: egcs

> 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.

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

* Re: An Ansi-C question or... Is egcs/gcc Ansi compliant?
  1998-12-30  2:25 An Ansi-C question or... Is egcs/gcc Ansi compliant? Enrique I.R.
  1998-12-30 19:37 ` Joe Buck
@ 1998-12-31  2:22 ` Martin v. Loewis
  1 sibling, 0 replies; 3+ messages in thread
From: Martin v. Loewis @ 1998-12-31  2:22 UTC (permalink / raw)
  To: esoft; +Cc: egcs

> Just playing with const:
[...]
> Why ignore egcs/gcc the const keyword such way?

The keyword is not ignored: you get a warning. This is ANSI compliant;
the compiler is required to diagnose the error, it may still chose to
compile the program (as an extension).

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

If you absolutely want compilation to fail, you should pass the flag
-pedantic-errors

> PS: I don't know this message is really on-topic here.

This was a good choice. Since you've suspected a bug,
egcs-bugs@cygnus.com would have been even better.

Regards,
Martin

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

end of thread, other threads:[~1998-12-31  2:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-30  2:25 An Ansi-C question or... Is egcs/gcc Ansi compliant? Enrique I.R.
1998-12-30 19:37 ` Joe Buck
1998-12-31  2:22 ` Martin v. Loewis

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).