Author Topic: small patch for codecompletion  (Read 5572 times)

Offline frithjofh

  • Regular
  • ***
  • Posts: 376
small patch for codecompletion
« 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
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: small patch for codecompletion
« Reply #1 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
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline frithjofh

  • Regular
  • ***
  • Posts: 376
Re: small patch for codecompletion
« Reply #2 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
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: small patch for codecompletion
« Reply #3 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
(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!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: small patch for codecompletion
« Reply #4 on: December 05, 2015, 04:17:52 pm »
The patch is in trunk now, thanks.
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.