Open stinos opened 8 years ago
Does an explicit cast to (unsigned char) also prevent the runtime breakpoint? That would seem clearer and would definitely avoid any unnecessary bitwise AND instructions.
No that doesn't prevent it (the truncation is still there, whether the cast is implicit or explicit). If you're concerned about casts not being optimized away I could make e.g. a function or macro narrow_cast which for msvc does the AND but for other toolsets is a no-op.
The result of adding two unsigned chars is an int, so assigning this again to unsigned char results in a narrowing cast. Afaik this is well-defined by the standard but code compiled with cl with all runtime checks enabled will trigger a breakpoint when e.g. scanline[i] + recon[i - bytewidth] yields a number > 255. Fix this, and make it clear what's happening, by and'ing with 0xFF (which should be discarded by any sane optimizer anyway).