Aharon
Aharon

Reputation: 137

Mixing of two #defines into one word

The convention of controls on my dialog is:

 #define DLG_NAME              1
 #define DLG_NAME_CONTROL_NAME 2  

I want to build a function which will know the control name, and has to get the defined value.
It's clear that I can't write int i = DLG_NAME + _ + CONTROL_NAME.

So how can I mix the first #define and another text to get the second #define value?

Upvotes: 1

Views: 280

Answers (1)

Matthias
Matthias

Reputation: 8180

I guess, what you are looking for is:

#define DLG_NAME_FIRST_COMBO 2    
#define CONTROL_NAME(x) DLG_NAME_##x

int i = CONTROL_NAME(FIRST_COMBO);

The way you suggested in your comment does not work, since the macro expression is not re-evaluated outside a definition.

Upvotes: 3

Related Questions