Is there a difference here?

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:33 UTC
Read the original article Hit count: 291

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 :)

Thank you in advance!

© Stack Overflow or respective owner

Related posts about c++

Related posts about best-practices