I’m looking to use:
#define
and
#if
to allow me to simulate potentially absent hardware during unit tests. What are the rules for using the #define statements?
i.e. what is its default scope? can I change the scope of the directive?
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.
As Chris said, the scope of #define is just the file. (It’s worth noting that this isn’t the same as ‘the class’ – if you have a partial type, it may consist of two files, one of which has symbol defined and one of which doesn’t!
You can also define a symbol project-wide, but that’s done with project properties or a compiler switch rather than being specified in source code.