News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

small patch for codecompletion

Started by frithjofh, December 02, 2015, 01:11:56 PM

Previous topic - Next topic

frithjofh

just a small path cleaning up a conditio in the line of

!A || (A && B)

is really the same as

!A || B
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

yvesdm3000

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
Clang based code completion for Code::Blocks:   [url="http://github.com/yvesdm3000/ClangLib"]http://github.com/yvesdm3000/ClangLib[/url]

frithjofh

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
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

oBFusCATed

Of course there are precedence rules in C++ also there is early exit in conditionals.

http://en.cppreference.com/w/cpp/language/operator_precedence
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

ollydbg

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.