I was wondering is it safe to do so?
wchar_t wide = /* something */;
assert(wide >= 0 && wide < 256 &&);
char myChar = static_cast<char>(wide);
If I am pretty sure the wide char will fall within ASCII range.
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.
assertis for ensuring that something is true in a debug mode, without it having any effect in a release build. Better to use anifstatement and have an alternate plan for characters that are outside the range, unless the only way to get characters outside the range is through a program bug.Also, depending on your character encoding, you might find a difference between the Unicode characters 0x80 through 0xff and their
charversion.