GCC options for strict C90 code?

I am trying to find what is the combination of gcc flags to use when testing strict C90 conformance. According to previous post: GCC options for strictest C code?, I should only need a --std=c90.

However here is what I tried:

$ cat t.c
#include <stdint.h> /* added in C99 */

int main()
{
  uint64_t t;
  return 0;
}
$ gcc -std=c90 -ansi -pedantic   t.c

The above does work well (no warnings/errors produced).

Does anyone knows of:

  • gcc flags to have strict ISO/IEC 9899:1990 conformance
  • A different compiler (tcc, clang...) with different set of flags ?
  • EDIT:

    Sorry for my wording, yes I would really like to mimic a strictly conforming C90 compiler, in other word it should fail if the code tries to use any feature added later (C99 comes to mind). So pthread include header ought to emit a warning when compiled in what GNU/GCC calls C90 mode (just like stdint.h header should produce a warning without C99). -pedantic nicely warns me about usage of long long , I do not see why it should not warn me about uint64_t .

    I used the terminology of ISO/IEC 9899:1990 as quoted from:

  • http://en.wikipedia.org/wiki/C_(programming_language)#ANSI_C_and_ISO_C
  • In 1990, the ANSI C standard (with formatting changes) was adopted by the International Organization for Standardization (ISO) as ISO/IEC 9899:1990, which is sometimes called C90. Therefore, the terms "C89" and "C90" refer to the same programming language.

    EDIT2:

    GCC documentation are actually quite clear:

    Some features that are part of the C99 standard are accepted as extensions in C90 mode, and some features that are part of the C11 standard are accepted as extensions in C90 and C99 modes.

    So my question is rephrased into:

  • Is there a compiler + standard include header on a linux system which strictly conforms to C90 ?

  • Keep in mind here that GCC itself is a conforming freestanding implementation of the C standard specified; such an implementation only supplies a small subset of the standard header files, and practically none of the actual functionality of the C standard library, instead relying on another party -- glibc on Linux systems, for instance -- to supply the C standard library's functionality.

    What you seek is something that not only warns you when you are using a C99/C11/GNU language feature that is not in C90, but when you use a library function that is not defined by C90 itself. Sadly, the compiler alone cannot do this for the reason stated above -- it is aloof to what libc it is used with. On glibc systems, the C standard library will pick up on the macros defined by -std=c90 or -ansi :

    The macro __STRICT_ANSI__ is predefined when the -ansi option is used. Some header files may notice this macro and refrain from declaring certain functions or defining certain macros that the ISO standard doesn't call for; this is to avoid interfering with any programs that might use these names for other things.

    and give you some help by turning off gratuitous extensions:

    If you compile your programs using 'gcc -ansi' , you get only the ISO C library features, unless you explicitly request additional features by defining one or more of the feature macros.

    However, this only covers extensions and POSIX-but-not-ISO C functions; it will not save you if a function's behavior is specified differently in ISO C and POSIX.1!


    C90 compliance doesn't mean that the compiler can't offer other headers that aren't mentioned in the C90 standard. ( sys/socket.h , for instance.) If you want to disallow these for some strange reason, you can pass the -I option to add an extra include path, and in that path put versions of all the C99-only headers which are simply #error Don't include me .

    链接地址: http://www.djcxy.com/p/86366.html

    上一篇: 了解MongoDB BSON文档大小限制

    下一篇: 严格C90代码的GCC选项?