Operator precedence in TerrainBlock::buildPolyList
by Andrew Haydn Grant · in Torque Game Engine · 05/19/2005 (2:21 pm) · 6 replies
I'm playing with my MSDEV workspace, and seeing what happens when I build Torque with all sorts of warnings that are normally turned off. Should I be worried about this one?
engine\terrain\terrCollision.cc(548) : warning C4554: '<<' : check operator precedence for possible error; use parentheses to clarify precedence
The offending line:
The MSVC help comment:
I don't grok the code this line is in, but if this is the intended behavior, I would expect it to be written differently:
It looks like surfaceKey is just an arbitrary handle, in which case it might never matter.
engine\terrain\terrCollision.cc(548) : warning C4554: '<<' : check operator precedence for possible error; use parentheses to clarify precedence
The offending line:
U32 surfaceKey = (xi << 16 + yi) << 1;
The MSVC help comment:
a = a << b + c; // C4554 // probably intended (a << b) + c, // but will get a << (b + c)
I don't grok the code this line is in, but if this is the intended behavior, I would expect it to be written differently:
U32 surfaceKey = xi << 16 + yi + 1;
It looks like surfaceKey is just an arbitrary handle, in which case it might never matter.
About the author
#2
07/12/2005 (1:10 pm)
Ok, I reviewed this bug; it looks like everything is actually just fine and the code is operating as intended. The << 1 is there to leave a bit for the two planes lower down. Bug #85 resolved.
#3
Leaving room for the extra bit as you say makes perfect sense.
07/12/2005 (1:42 pm)
I am more worried about the "16 + yi" part. If surface key is supposed to have the top 16 bits match xi and the bottom 16 match yi, that's not what's happening. Instead, we're shifting xi over by yi. Unless yi is less than 32, xi is going to vanish completely.Leaving room for the extra bit as you say makes perfect sense.
#4
const U32 surfaceKey = ((xi << 16) | yi) << 1;
Look good?
07/12/2005 (2:12 pm)
Here's the current math:const U32 surfaceKey = ((xi << 16) | yi) << 1;
Look good?
#5
Yet another place where a line of code contains more information than all my blathering....
I'm sorry if I came across as pedantic. That wasn't my goal. When I read your post, I was worried that the << 1 had eclipsed the other piece. But you were already on top of things. :-)
07/12/2005 (2:38 pm)
Looks great!Yet another place where a line of code contains more information than all my blathering....
I'm sorry if I came across as pedantic. That wasn't my goal. When I read your post, I was worried that the << 1 had eclipsed the other piece. But you were already on top of things. :-)
#6
Also, the slow way forums works means I had time to digest your thought and fix my first cut at the math, which was in fact wrong. ; )
07/12/2005 (3:30 pm)
Nah, it's all good. We must strive for perfection together - for if we are apart we will surely fail.Also, the slow way forums works means I had time to digest your thought and fix my first cut at the math, which was in fact wrong. ; )
Associate Kyle Carter