Re: -std=c90 -pedantic-errors and <stdint.h>

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

 



On 2017-06-01 13:14:50 +0200, David Brown wrote:
> On 31/05/17 01:23, Vincent Lefevre wrote:
> > On 2017-05-30 23:04:02 +0200, Florian Weimer wrote:
> >> * Vincent Lefevre:
> >>
> >>> Is it normal that -std=c90 -pedantic-errors allows to use
> >>>
> >>> #include <stdint.h>
> >>>
> >>> ?
> >>
> >> Yes.  It's difficult where to draw the line.  <inttypes.h> was
> >> apparently available with some C90 compilers, so it would make sense
> >> to allow it in C90 mode.  But this means that it wouldn't be
> >> completely out of line to accept <stdint.h>, too.
> 
> I have used C90 compilers that provided a <stdint.h> too.
> 
> And since C90 does not define a <stdint.h>, an implementation or user is
> free to put a file called "stdint.h" in a directory that is searched for
> system includes - a compiler cannot arbitrarily blacklist a header name
> in a standard that does not mention that name!

Note that with -pedantic-errors, this is more than a compiler,
there are also strong compatibility tests. Without -pedantic-errors,
<stdint.h> would *not* be blacklisted. Ditto if the user uses some
-Wno- option to disable the associated warning.

If you want an example:

  -Woverlength-strings
      Warn about string constants that are longer than the "minimum
      maximum" length specified in the C standard.  Modern compilers
      generally allow string constants that are much longer than the
      standard's minimum limit, but very portable programs should avoid
      using longer strings.

      The limit applies after string constant concatenation, and does not
      count the trailing NUL.  In C90, the limit was 509 characters; in
      C99, it was raised to 4095.  C++98 does not specify a normative
      minimum maximum, so we do not diagnose overlength strings in C++.

      This option is implied by -Wpedantic, and can be disabled with
      -Wno-overlength-strings.

> > Now, what actually mattered in my case was the use of (u)intmax_t.
> > For instance, consider the following program:
> > 
> > #include <stdio.h>
> > #include <stdint.h>
> > #include <limits.h>
> > 
> > int main (void)
> > {
> >   uintmax_t i = -1;
> >   printf ("%d\n", i > ULONG_MAX);
> >   return 0;
> > }
> > 
> > In C90, "long" is the largest type, so that one should always expect
> > the output 0. But:
> 
> "long" is the largest standards-mandated type in C90, but it is not
> necessarily the largest type available.  An implementation is allowed to
> provide additional types, even in "pedantic" C90 mode.

I disagree. Such types should yield a warning in "pedantic" C90 mode,
just like other features that are not portable (see the above example
with -Woverlength-strings, implied by -Wpedantic). IMHO, using
intmax_t with an arbitrary C90 compiler is more problematic than
using an overlength string (to some reasonable extent).

> If you want to stick to C90, and you want to have a uintmax_t that
> matches "long", then I suggest you don't include headers that are not
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
> relevant for C90, and define the types yourself.

But that's the goal of -pedantic-errors!!! By using this option, I
want to be able to detect the unconditional inclusion of <stdint.h>
(actually I want it to be rejected by the autoconf test, which is
the same thing in practice).

>  Perhaps start with:
> 
> #ifdef __STRICT_ANSI__
> typedef long int intmax_t;
> typedef unsigned long int uintmax_t;
> #else
> #include <stdint.h>
> #endif

The goal of -pedantic-errors is to *detect* that the developer writes
something like the above instead of just:

#include <stdint.h>

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux