I just had a little bug in my code. In the WindowsAPI, there's this alias:
alias ubyte BYTE;
Unfortunately I didn't check for this, and I erroneously assumed BYTE was a
signed value (blame it on my lack of coffee). So when I used code like this:
alias Tuple!(byte, "red", byte, "green", byte, "blue") RGBTuple;
RGBTuple GetRGB(COLORREF cref)
{
RGBTuple rgb;
rgb.red = GetRValue(cref);
rgb.green = GetGValue(cref);
rgb.blue = GetBValue(cref);
return rgb;
}
The rgb fields would often end up being -1 (Yes, I know all about how signed vs
unsigned representation works). My fault, yes.
But what really surprises me is that these unsigned to signed conversions
happen implicitly. I didn't even get a warning, even though I have all warning
switches turned on.
I'm pretty sure GCC would complain about this in C code. Visual Studio
certainly complains if I set the appropriate warnings, examples given:
warning C4365: '=' : conversion from 'unsigned int' to 'int', signed/unsigned
mismatch
warning C4365: '=' : conversion from 'unsigned short' to 'short',
signed/unsigned mismatch