Any difference in compiler behavior for each of these snippets?
Posted
by HotHead
on Stack Overflow
See other posts from Stack Overflow
or by HotHead
Published on 2010-04-09T17:27:41Z
Indexed on
2010/04/09
17:43 UTC
Read the original article
Hit count: 304
Please consider following code:
1.
uint16 a = 0x0001;
if(a < 0x0002)
{
// do something
}
2.
uint16 a = 0x0001;
if(a < uint16(0x0002))
{
// do something
}
3.
uint16 a = 0x0001;
if(a < static_cast<uint16>(0x0002))
{
// do something
}
4.
uint16 a = 0x0001;
uint16 b = 0x0002;
if(a < b)
{
// do something
}
What compiler does in backgorund and what is the best (and correct) way to do above testing?
p.s. sorry, but I couldn't find the better title :)
EDIT:
values 0x0001 and 0x0002 are only example. There coudl be any 2 byte value instead.
Thank you in advance!
© Stack Overflow or respective owner