#11 gcc -Wundef failures


My generated scanner contains the lines:

#if __STDC_VERSION__ >= 199901L


#if __STDC__

These will fail to compile with gcc with the -Wundef
flag. I notice that the "defined __STDC_VERSION__"
check was removed from:

./flexint.h:8:#if __STDC_VERSION__ >= 199901L



The code as-is is perfectly legal C and C++, so you'd
be perfectly within your rights to reject this bug.
But... -Wundef has found bugs for us and, I guess,
enough others that they added it to gcc. So we would
be happier if the "defined" check were reinstated.

Well, I've done my bit by reporting it. Now I'm off to
find out why __STDC_VERSION__ isn't defined in our
build environment...


  • John43

    John43 - 2006-03-20
    • assigned_to: nobody --> john43
  • John43

    John43 - 2006-03-20

    Logged In: YES

    Ok, first, does it fail to compile or does it just emit a
    warning? If it's just a warning, is it a harmless warning or
    does it expose a real, solid bug? In other words, will the
    scanner misbehave at runtime due to this?

    We know C99 requires __STDC__ to be #define'd as 1.

    Certain versions of GCC will only #define __STDC__ to 1 if
    given the --std=c99 flag. Which is bizarre. Other compilers
    (Sun cc) do not follow the standard at all. So the question
    is how should we resolve this? Sun's cc is clearly incorrect
    with respect to C99. But gcc is not incorrect in the sense
    that you CAN make it work with an option, but most people do
    not use the --std=c99 option, and we certainly don't wish to
    require them to.

    Here are my thoughts: If there is a true bug here, and we
    can patch it to work on ALL systems, then we should do it.
    If it is merely a harmless warning, then we should just
    ignore it and wait for the compilers to be fixed.

  • Martin Dorey

    Martin Dorey - 2006-03-21

    Logged In: YES

    I'm sure it's just a harmless warning. However, we like to
    do as much of our compilation as possible with -Werror.
    That's been a great help to us, though I realize it's not
    always that you're in the fortunate position where it's
    practical. I've disabled this flag for the few scanners we
    compile. I'm sure the flex-generated code is beyond
    reproach but I'm less sure that the user code we have in the
    scanner files is.

    Wouldn't the only side-effect of adding the defined check here:

    #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L

    ... be to make this compile with -Wundef (and -Werror) on
    pre-19901L systems? The __STDC__ case is, by the sound of
    it, more controversial. It might be too gruesome to
    contemplate having the defined check in one #if and not in
    the other but it wouldn't be worthless. The __STDC__ test
    is in a non-C++ branch and the version of gcc that I'm using
    does define __STDC__ to 1. It's only __STDC_VERSION__ that
    it complains about - I was a bit over-enthusiastic in the
    original report. Given that some compilers define __STDC__
    but not to any value, whereas I doubt any compiler defines
    __STDC_VERSION__ to no value, an inconsistency between the
    two #ifs could reasonably be said to be the compilers' fault.

  • John43

    John43 - 2006-03-21

    Logged In: YES

    This has been patched. Thank you.

  • John43

    John43 - 2006-03-21
    • labels: 595149 --> Warning messages
    • status: open --> closed-accepted
  • Martin Dorey

    Martin Dorey - 2006-03-21

    Logged In: YES

    Much appreciated.

  • David Fang

    David Fang - 2006-07-04

    Logged In: YES

    This affects me too, but I see that the patch has been applied.
    You have my thanks as well.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks