Issue about using C99 headers in C90 (was Re: -std=c90 -pedantic-errors and <stdint.h>)
Xi Ruoyao
ryxi@stu.xidian.edu.cn
Thu Jun 1 20:10:00 GMT 2017
On 2017-05-30 17:10 +0200, Vincent Lefevre wrote:
> Is it normal that -std=c90 -pedantic-errors allows to use
>
> #include <stdint.h>
>
> ?
>
> This is annoying when one wants to check for code portability
> (and bugs).
Let's ask libc developers and get their opinion about using
stdint.h in C90...
Hi all,
There has been an argue in gcc-help about using stdint.h (or
other C99 headers) in C90. Some people think that's not
portable. Â They expect an error or a warning when they include
stdint.h in C90.
There are some options:
0) Do nothing, if we have a good reason.
1) Let GCC complains the header with name "stdint.h" in C90 mode,
  maybe with a flag. (Maybe -Wnew-std-headers?)
  I think it's stupid to make the decision according to the
  filename.
2) Disable stdint.h in C90, using something like
  #if defined(__STRICT_ANSI__) && __STDC_VERSION__ < 199901L
  #error "This is a C99 header.  Please use -std=c99."
  #endif
  Maybe we need to check feature test macros (_POSIX_C_SOURCE
  etc) as well.
3) Warn about using stdint.h in C90.
  #if defined(__STRICT_ANSI__) && __STDC_VERSION__ < 199901L
  #warning "This is a C99 header.  Recommend to use -std=c99."
  #endif
4) Let GCC define something like "__PEDANTIC__" with
  "-Wpedantic" and write...
  #if defined(__STRICT_ANSI__) && __STDC_VERSION__ < 199901L
  #if __PEDANTIC__ > 1 /* with -Werror=pedantic.  */
  #error "This is a C99 header.  Please use -std=c99."
  #elif __PEDANTIC__ > 0 /* with -Wpedantic.  */
  #warning "This is a C99 header.  Recommend to use -std=c99."
  #endif
  in stdint.h.
5) Let GCC accept a strange pragma to check C Standard version:
  #pragma GCC require(stdc, 199901L)
  And GCC would produce pedantic warning/error according to
  the flag while it see this pragma.
Which option should we take?
--
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University
More information about the Gcc-help
mailing list