Is there a way of guarding against the resulting binary from the code in this question? Ideally by way of an error at compile time. Example code from the question:
unsigned int nVal = 0;
nVal = -5; // no error!
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.
If you are using g++, the switch
-Wsign-conversionwill warn about the conversion, and-Werrorwill make that warning an error.