What does the C++ language definition promise about casting a char to bool then back to char again?
char original = 255;
bool next = original;
char final = next;
Also, what do most compilers do in this case beyond what the language guarantees?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will give a value of zero or one, depending on whether the original value was zero or non-zero.
Converting to
boolgives a value oftrueorfalse:Converting back to
charconvertsfalseto zero, andtrueto one: