user1806687
user1806687

Reputation: 920

One #define two values

I am writting the code in C and compiled in GCC. As the tittle says, how can I assign two values to the same #define statement. I don't mean to assign them like enum type or something, but in this way. Lets say I have a macro SET_SOMETHING(num1,num2). How can I replace num1,num2 with ONE #define statement named for example: SOME_NUMBERS. So when I will be "calling"(don't know if I am right saying calling) a macro it would look like this: SET_SOMETHING(SOME_NUMBERS). I already tried the obvious way doing #define SOME_NUMBERS 1,5 but just wont work for some reason, why? Doesnt the define just replaces the code?

If this would be possible, how would I then go to extract only the first or the second number from the define SOME_NUMBERS ?

Thank you for your help!

Upvotes: 0

Views: 384

Answers (1)

Jens Gustedt
Jens Gustedt

Reputation: 78923

When your macro parses SOME_NUMBERS it already has tried to separate the two arguments. You'd have to have two macros in a row

#define INNER_MACRO(A, B) dosomething(A, B)
#define OUTER_MACRO(...) INNER_MACRO(__VA_ARGS__)

Upvotes: 1

Related Questions