"Comparison to integral constant is useless; the constant is outside the range of type 'int'"

C

Claire

"Comparison to integral constant is useless; the constant is outside the
range of type 'int'"
How can I fix this compiler warning, please, for the following pseudocode?

int m_nError;
m_nError = somedriverapi.DoSomething();
if (m_nError != 0x8010002F) foobar; << compiler warning here

thankyou
Claire
 
V

Vadym Stetsiak

Hello, Claire!

Warning is generated, because value 0x8010002F exceeds the valid range of
int type.
Due to sign information max value of int is 2^31

You can use uint instead of int. uint max value is 2^32. Or use cast to
uint.
if ((uint)m_nError != 0x8010002F) foobar;

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com


You wrote on Mon, 3 Sep 2007 10:52:42 +0100:

C> "Comparison to integral constant is useless; the constant is outside
C> the range of type 'int'"
C> How can I fix this compiler warning, please, for the following
C> pseudocode?

C> int m_nError;
C> m_nError = somedriverapi.DoSomething();
C> if (m_nError != 0x8010002F) foobar; << compiler warning here

C> thankyou
C> Claire
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top