I am facing a strange issue, working on my mac osx lion (under xcode4/clang, though it is reproducible with gcc4.2).
It seems, that I can not assign any value above 127 for a unsigned char variable. So, when I assign
v = (unsigned char) 156;
or, simply
std::cout << (unsigned char) 231 << std::endl;
my program does not produce any output.
When I run this code
std::cout << "Unsigned chars range up to " << UCHAR_MAX << std::endl;
I get the following output:
Unsigned chars range up to 255
However, when I run something like this, the program generates outputs up to some different arbitrary value (such as c = 114, c = 252, etc etc) each time. for(unsigned char c = 0; c < CHAR_MAX; c++) std::cout << "c = " << 2*c << std::endl;
Changing the CHAR_MAX to UCHAR_MAX, the program ends without an output again :(
Thanks in advance
v = (unsigned char)156; std::cout << (unsigned)v << '\n';
. - ildjarnunsigned int
) did help! - Nikhil J Joshi