X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f X-Recipient: djgpp-workers AT delorie DOT com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=tRURdlVRLqcIv1CbySW3HvteFJFYAvED70zcTqtbNgI=; b=aijdMTLKr2U9KuCeOREi9eNvB16WSP2YEvJHspqEMDkurVnmeMaH+N8VQYtsWs6JSU fB1ru5Wd3NunyHeec0UApL/uqvjuEoOX1vdaCs7FY8D3qI0/EZ9wstEyEBGBSrlAauct krXzf95mhXcJbDyBDOoaqS29mHomQbqqDRlIIpvK7HcYXjBQTYKc5SkdjhwAxN6vxZvs I1SH5tVsq6+P4mts5WH1yoTe9BiP3rT1b+/PmJWXJ++0MiaBKfcWqEmsUb12eU/MY08M QMM5oOK0oLO1PWfnOZH/7PKZpREae8pqcgv+nRd32MrxoqnDqU5niyrvBvP1sW1EH3mX AkXQ== MIME-Version: 1.0 In-Reply-To: <504CD18B.1060207@iki.fi> References: <504CD18B DOT 1060207 AT iki DOT fi> Date: Sun, 9 Sep 2012 16:19:51 -0500 Message-ID: Subject: Re: Invalid tests for __STDC_VERSION__ in DJGPP header files From: Rugxulo To: djgpp-workers AT delorie DOT com Content-Type: text/plain; charset=ISO-8859-1 Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Hi, On Sun, Sep 9, 2012 at 12:27 PM, Andris Pavenis wrote: > -_STDC_VERSION__ is not defined in many cases any recent GCC version. It is > only seems to be defined in several cases depending on the command line > parameter -std and for C language only Most C compilers seem to only define __STDC__ when "ANSI" compatibility is turned on. GCC however must consider itself "close enough" by default ("gnu89") that it defines it anyways. However, anything beyond that is (usually) turned off. Apparently GCC (from gcc.info) claims "-std=c89" and "-std=c90" and "-ansi" are all the same thing. (Though I swear I halfway read somewhere recently that __STDC_VERSION__ was first defined in ISO 1990. Dunno!) By default, "gnu89" disables trigraphs (dunno what else), so it's close but not quite strict, hence the obvious needs for other switches (-ansi -pedantic). > Some examples: > > [andris AT ap ~]$ i586-pc-msdosdjgpp-gcc -dD -E -std=c99 -x c /dev/null | grep > STDC > [andris AT ap ~]$ i586-pc-msdosdjgpp-gcc -dD -E -std=c90 -x c /dev/null | grep > STDC > [andris AT ap ~]$ i586-pc-msdosdjgpp-gcc -dD -E -std=c89 -x c /dev/null | grep > STDC > [andris AT ap ~]$ i586-pc-msdosdjgpp-gcc -dD -E -std=c9x -x c /dev/null | grep > STDC > [andris AT ap ~]$ i586-pc-msdosdjgpp-gcc -dD -E -std=c11 -x c /dev/null | grep > STDC You forgot "-std=iso9899:199409 (aka, C94 or C95 or AMD1 or NA1), which first added all that wchar crud. :-P > As the result tests used in header files like > > #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ > || !defined(__STRICT_ANSI__) > > are invalid. Dunno, it's hard to guess what's going on there. "#if BLAH" works only if BLAH is non-zero, right? (Allegedly some old compilers defined __STDC__ to zero to show lack of full compliance, ugh.) So a simple "#define BLAH" should define it to equal 1, right? > I see several possibilities > 1) assume that the version is new enough when __STDC_VERSION__ is not > defined > #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199901L) \ > || !defined(__STRICT_ANSI__) > 2) remove tests for version 199001 or later at all (one may need tests for > newer > versions though) I assume you mean "199901L" (C99) here. Dunno about removing anything, but if GCC was going to switch to "gnu99" by default, they probably would've done it by now (as Clang has from the beginning). > 3) require __STDC_VERSION__ to be defined for very old GCC versions (as far > as > I tested gcc-3.4.4 is considered not very old) Old DJGPP 2.95.3 seems to say C94 by default (as does OpenWatcom, IIRC), and that's with DJGPP 2.03p2 and no fancy switches. Even using "-std=c9x" [sic] doesn't change that. Seems 3.0.4 corrected it as default it doesn't define __STDC_VERSION__. And it does indeed define it for "-std=c99" [sic]. Though if you use "-std=iso9899:199409", it will define it also (as appropriate). > Use of the broken test for __STDC_VERSION__ prevents libstdc++-v3 (GCC-4.8.0 > development versions from some last weeks) building OK due to actual > contents of stdint.h being compiled out. Variant 1 is verified to fix the > build (only tested cross-native build from Linux) I don't know what versions are recommended or used or tested by default. DJ and/or Eli will have to chime in. I'm pretty sure that 2.95.3 is way too old, but I would blindly guess that 3.4.4 may? be acceptable??