The Visual Studio compiler does not seem to warn about signed / unsigned assignments, only when comparing. For example, the code below will generate a warning in an if statement, but not for initial purposes.
Is there anyway to get them to catch them? I'm already in W4, but I thought (hopes) that somewhere there might be a different setting.
Thank,
int foo(void)
{
unsigned int fooUnsigned = 0xffffffff;
int fooSigned = fooUnsigned;
if (fooSigned < fooUnsigned)
{
return 0;
}
return fooSigned;
}
Update:
Quamrana is right, this is controlled by warning 4365, which is disabled by default, even on W4. However, you can explicitly enable it for a given warning level, for example:
#pragma warning (4 : 4365)
The result is:
warning C4365: 'initializing' : conversion from 'unsigned int' to 'int', signed/unsigned mismatch
source
share