This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Issue about using C99 headers in C90 (was Re: -std=c90 -pedantic-errors and <stdint.h>)
- From: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- To: libc-help at sourceware dot org
- Cc: ryxi at stu dot xidian dot edu dot cn, Vincent Lefevre <vincent+gcc at vinc17 dot org>, gcc-help at gcc dot gnu dot org, Florian Weimer <fw at deneb dot enyo dot de>, David Brown <david at westcontrol dot com>, Jonathan Wakely <jwakely dot gcc at gmail dot com>, Marc Glisse <marc dot glisse at inria dot fr>
- Date: Fri, 02 Jun 2017 04:10:28 +0800
- Subject: Issue about using C99 headers in C90 (was Re: -std=c90 -pedantic-errors and <stdint.h>)
- Authentication-results: sourceware.org; auth=none
- References: <20170530151051.GA30477@zira.vinc17.org>
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