A char
is always a byte, so whether your platform is 16-bit or 64-bit words doesn't really matter (though if you're using a system with CHAR_BIT != 8
, we'll talk!). What's probably of more consequence is that your 16-bit compiler (yes, I'm assuming Turbo C++) is from the 1980s, a decade before the first standard edition of C++, so it behaves a bit differently overall.
In this case, it is less tolerant of the value 256
, which is actually larger than can be stored in a char
(signed or otherwise). I'd say it's "wrong", but it's hard to be non-compliant to a standard that didn't exist at the time. Turbo C++ is pretty much free to do its own thing, in that sense — it's not actually C++, in the way that we understand the term "C++" today.
I would expect your Visual Studio compiler to emit a compiler warning... and then initialise the unsigned char
using wraparound, as that's how unsigned values work.