Web lists-archives.com

Re: [Mingw-users] Does MinGW not support -std=c++11 flag?






On Tue, Oct 18, 2016 at 3:39 PM, Keith Marshall <keithmarshall@xxxxxxxxxxxxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 17/10/16 20:05, DAVENPORT, MARC wrote:
[concerning partial inclusion guard logic in <wchar.h>]
> I don't quite understand the logic of the line you used to fix the
> inclusion though (The comment confuses me) :

Inverse logic does tend to be confusing, especially when combining
negated conditions.  I've tried to make it clearer, in the published
version, but basically the guarded code is always exposed the first
time that part of <wchar.h> is read, but not if it is read a second
time.  For it to be read a second time, its first time *must* have
been as a result of partial inclusion by <string.h>, which results
in _STRING_H being defined, so if *both* _WCHAR_H and _STRING_H are
defined:

  #if defined _WCHAR_H && defined _STRING_H

then it is implicit that this is the second time of reading.  However,
if __STRICT_ANSI__ is defined, then the partial inclusion of <wchar.h>
by <string.h> is suppressed, so _STRING_H may be defined *without* the
assumed first reading of this code having occurred.  Thus, to identify
this case we need to check for the qualified sub-_expression_:

  #if defined _STRING_H && ! defined __STRICT_ANSI__

or, combining the two sub-expressions to identify a second reading:

  #if  defined _WCHAR_H \
   && (defined _STRING_H && ! defined __STRICT_ANSI__)

Finally, we need to invert the logic, to *exclude* the guarded code on
second reading, so we end up with[*]:

  #if ! (defined _WCHAR_H \
   &&   (defined _STRING_H && ! defined __STRICT_ANSI__))

[*]: Yes, I know there are more parentheses there than may be strictly
necessary; IMO, they should help to clarify the logical intent for the
benefit of human readers.
 
Thanks for the explanation. If I remember my logic correctly, it follows that there is an equivalent form using associativity and DeMorgan's laws.

   !(A && (B && !C))   == Use Associativity
   !((A && B) && !C)   ==  Substitute D for (A && B)
   !(D && !C)              ==  Use DeMorgan's law to distribute NOT
   !D || C                    ==  Substitute (A && B) for D
   !(A && B) || C         == Use DeMorgan's law to distribute NOT
-----------------------------------
   !A || !B || C

 This would mean that the equivalent _expression_ would be :

if !defined _WCHAR_H || !defined _STRING_H || defined __STRICT_ANSI

However, in the header wchar.h, _WCHAR_H is always defined so the _expression_ would actually simplify to :

if !defined _STRING_H || defined __STRICT_ANSI

I think my logic is correct. Does that make sense? This way it will be included if _STRING_H is not defined (in the case of wchar.h being included first) or if __STRICT_ANSI is defined, in which case the first reading would have been suppressed.

Hopefully I'm being helpful and not confusing the issue. In any case I appreciate the fix.

Marc D.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe