I have seen #ifndef ABC and #if !defined (ABC) in the same C source file.
Is there subtle difference between them?
(If it is a matter of style, why would someone use them in the same file)
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.
No, there’s no difference between the two when used that way. The latter form (using
defined()) is useful when the initial#ifor one of the subsequent#elifconditions needs a more complex test.#ifdefwill still work, but it might be clearer using#if defined()in that case. For example, if it needs to test if more than one macro is defined, or if it equals a specific value.The variance (using both in a file) could depend on specific subtleties in usage, as mentioned above, or just poor practice, by being inconsistent.