#207 __STRICT_ANSI__ & _POSIX_

header (101)

mingw32 puts a lot of declarations (namely - from stdlib.h) under #ifndef __STRICT_ANSI__
Some 3rd-party programs (namely - libtool) make an assumption that defined(__STRICT_ANSI__) means that these declarations are absent (namely - _putenv) and that they (programs) are free to make their own declarations.
mingw64 uses __STRICT_ANSI__ for non-ANSI floating-point functions, but its usage in stdlib.h is very limited. mingw64, however, uses _POSIX instead of __STRICT_ANSI__ for most non-ANSI declarations (mingw32 makes almost no use of _POSIX, by the way).
Is it correct to use _POSIX as a synonym to __STRICT_ANSI__?
Anyway, this mismatch might cause re-declaration warnings/errors in mingw32-aware programs.

How to fix:

Not sure. Probably the best way is to add extra || !defined(__STRICT_ANSI__) in some places which are only protected by _POSIX at the moment.


  • LRN

    LRN - 2010-12-29
  • LRN

    LRN - 2010-12-29

    (actually, it's "_POSIX_", with trailing underscore)

  • LRN

    LRN - 2010-12-29

    A bit of context:
    libtool testcase compiles a libtool wrapper with -std=c89 (so-called `restrictive' cflag) and -Werror to make sure libtool C-wrapper code is standard-compliant.
    GCC defines __STRICT_ANSI__ because of that. However, mingw-w64 does not disable non-ANSI declarations when __STRICT_ANSI__ is defined, it does that only when _POSIX_ is defined. Libtool doesn't know that, and (seeing that __STRICT_ANSI__ is defined) declares _putenv(), which conflicts with mingw-w64 declaration.

    Out-of-context: ANY code compiled with -std=c89 will NOT emit all the warnings and errors it should emit about non-ANSI functions (usually something along the lines of `foo is defined in-place'), making -std=c89 somewhat less useful (and actually broken, if your intention was to make your code strictly ANSI).

    Out of curiosity: what makes GCC define _POSIX_? It doesn't look like a C-dialect option. I've taken a closer look at mingw32 headers, and it doesn't seem that mingw32 knows anything about _POSIX_ (it does have _POSIX_SOURCE, but that's different and is defined by user).


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks