Sometimes I write code like
if (ptr)
ASSERT(ptr->member);
instead of
ASSERT(!ptr || ptr->member);
because it’s more straightforward IMO. Would the redundant comparison remain in the release build?
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.
I’d say that depends on your compiler.
In release mode, the
ASSERTmacro won’t evaluateptr->memberand will resolve to a trivial expression that the compiler will optimize out, but theifstatement and the associated comparison will remain as is.However, if the compiler is smart enough to determine that the condition does not have any side effect, it might optimize the entire
ifstatement away. Compiling to assembly (using the /FA option) would give you a definite answer.