Find this in the qt documentation.
What is the difference between
#if defined(Foo) && Foo == 0
and
#if Foo - 0 == 0
As far as I understand the latter also will be false if Foo is undefined? Where can I read about this?
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
Foois undefined, then the latter will translate towhich is true, not false. Remember that under
#ifall undefined identifiers are replaced with literal0(once alldefined()operators are evaluated, of course). That applies even to preprocessing tokens that match language keywords. In C language all keywords are replaced with0in this context. In C++ keywordstrueandfalseare exempt from replacement, while all other keywords are replaced.(BTW, that means that in C
truewill be quietly replaced with0if<stdbool.h>is not included, and with1if<stdbool.h>is included.)Meanwhile
is false when
Foois undefined. So, here’s your difference.The Qt documentation does indeed seem to suggest that the former is the same as the latter. I don’t know why they do that, since they are certainly not equivalent. It appears to be an error in Qt docs.