Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: frithjofh on December 02, 2015, 01:11:56 pm

Title: small patch for codecompletion
Post by: frithjofh on December 02, 2015, 01:11:56 pm
just a small path cleaning up a conditio in the line of

!A || (A && B)

is really the same as

!A || B
Title: Re: small patch for codecompletion
Post by: yvesdm3000 on December 02, 2015, 03:18:50 pm
Beware of this construct. There are no precedence rules for logical operations so the compiler can choose to make

!A  || B && C

into

!(A || B&&C)

or

(!A) || B && C

Been bitten by this myself before... It looks like compilers even take a space into account and treat it differently if there is a space between the ! and A or not.

Yves
Title: Re: small patch for codecompletion
Post by: frithjofh on December 02, 2015, 04:00:47 pm
the standard does give precedence rules for logical operators...

it states clearly that the logical not is of higher precedence than && and this higher than ||

it would have to be a bad implementation of the compiler

and remark the parenthesis too. they are like that in the code. this is not about left tor right or right to left ordering...

but, heck, maybe I am wrong ... I'll stand corrected gladly

thx for the feedback
Title: Re: small patch for codecompletion
Post by: oBFusCATed on December 03, 2015, 04:49:39 am
Of course there are precedence rules in C++ also there is early exit in conditionals.

http://en.cppreference.com/w/cpp/language/operator_precedence
Title: Re: small patch for codecompletion
Post by: ollydbg on December 05, 2015, 04:17:52 pm
The patch is in trunk now, thanks.