1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Aharon
  • 117
  • 1
  • 1
  • 14
  • Close enough: http://stackoverflow.com/questions/6503586/what-does-in-a-define-mean?lq=1 – chris May 30 '13 at 08:14
  • As chris suggested, you can use the `##` operator to combine macro names. However, I do not understand what you want to achieve. Do you want to get `1_2` as an identifier ? (its is not a valid one). – Matthieu Rouget May 30 '13 at 08:19
  • No. I want the preprocessor will translate `int i = DLG_NAME_CONTROL_NAME`. – Aharon May 30 '13 at 08:24
  • I'll explain better: I want to create some classes derived from common control class, and I'll write `#define DLG_NAME_FIRST_COMBO 2` and `#define CONTROL_NAME FIRST_COMBO`, and in the class's function I'll write `int i = DLG_NAME##CONTROL_NAME`. Each class will operate it as defined in it. Am I right? – Aharon May 30 '13 at 08:46

1 Answers1

3

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.

Matthias
  • 8,018
  • 2
  • 27
  • 53