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?

4
  • Close enough: stackoverflow.com/questions/6503586/… Commented May 30, 2013 at 8: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). Commented May 30, 2013 at 8:19
  • No. I want the preprocessor will translate int i = DLG_NAME_CONTROL_NAME. Commented May 30, 2013 at 8: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? Commented May 30, 2013 at 8:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.