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





PostPosted: Mon Sep 03 03:04:07 PDT 2007 Top

Visual C#.Net >> "Comparison to integral constant is useless; the constant is outside the range of type 'int'" "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

DotNet89  
 
 
Vadym





PostPosted: Mon Sep 03 03:04:07 PDT 2007 Top

Visual C#.Net >> "Comparison to integral constant is useless; the constant is outside the range of type 'int'" 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