Re: How to get autoconf to respect CC="gcc -std=c89"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2023-10-08, Niels Möller <nisse@xxxxxxxxxxxxxx> wrote:
> I would have expected that every input that is valid c89 also is valid
> c99, so that support for c99 strictly implies support for c89. But there
> may be some corner case I'm not aware of.

It is not true in general that a valid C89 program is also valid
C99, but it is essentially always the case for "normal" programs and
especially for "portable" programs which simply have to deal with the
fact that you can't really rely on any compiler providing perfect
strict standards conformance modes.

The most obvious difference is probably that "restrict" can be used
as an identifier in C89 (and it is not reserved anywhere) but this is
disallowed in C99 as "restrict" is lexically a keyword.

Furthermore, it is also not true that a program valid for both standards
will necessarily do the same thing.  It is easy to construct examples of
such behaviour differences deliberately but it probably never happens
inadvertently.

Here's one example of such a program (compare output when compiled
with gcc -std=c89 versus gcc -std=c99):

  #include <stdio.h>

  int main(void)
  {
    printf(
      "the compiler parses comments like C%d\n", 88 + 11 //**/ 11
    );
    return 0;
  }

Here's another:

  #include <stdio.h>

  enum { VER = 99 };
  int main(void)
  {
     if ((enum { VER = 89 })0)
        ;
     printf("the compiler implements block scopes like C%d\n", VER);
     return 0;
  }

Cheers,
  Nick





[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux