I have
#define ADD 5
#define SUB 6
Can I print ADD and SUB given their values 5 and 6?
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.
The names of the
defined symbols are removed by the preprocessor, so the compiler never sees them.If these names are important at runtime, they need to be encoded in something more persistent than just preprocessor symbol names. Perhaps a table with strings and integers:
This uses the stringifying preprocessor operator
#to avoid repetitions.With the above, you can trivially write look-up code: