B
badc0de
Hello..
a header file of one of my project has macro definitions like this
(for example)
#define PART_A_SORT_1_LABEL_STRING1 100
#define PART_A_SORT_1_LABEL_STRING2 200
#define PART_A_SORT_1_LABEL_STRING3 300
#define PART_A_SORT_1_LABEL_STRING4 400
#define PART_A_SORT_1_LABEL_STRING5 500
....
#define PART_A_SORT_7_LABEL_STRING1 1100
#define PART_A_SORT_7_LABEL_STRING2 3200
#define PART_A_SORT_7_LABEL_STRING3 2300
#define PART_A_SORT_7_LABEL_STRING4 1400
#define PART_A_SORT_7_LABEL_STRING5 6500
so, I tried to make a Macro defines another macros like this.
#define MY_DEFINE(PART_SORT, C1, C2, C3, C4, C5) \
#define PART_SORT##_LABEL_STRING1 C1 \
#define PART_SORT##_LABEL_STRING2 C2 \
#define PART_SORT##_LABEL_STRING3 C3 \
#define PART_SORT##_LABEL_STRING4 C4 \
#define PART_SORT##_LABEL_STRING5 C5
yeah, I thought the first ugly, big bulk of definitions will be
compacted like this.
MY_DEFINE(PART_A_SORT_1, 100, 200, 300, 400, 500)
....
MY_DEFINE(PART_A_SORT_7, 1100, 3200, 2300, 1400, 6500)
but I found #define treats '#' and '##' special. ## concats, # makes
string.
Now I guess you know what I'm trying to do.
Is there WAY to achieve this? or
REASON why I cannot?
Reguards.
a header file of one of my project has macro definitions like this
(for example)
#define PART_A_SORT_1_LABEL_STRING1 100
#define PART_A_SORT_1_LABEL_STRING2 200
#define PART_A_SORT_1_LABEL_STRING3 300
#define PART_A_SORT_1_LABEL_STRING4 400
#define PART_A_SORT_1_LABEL_STRING5 500
....
#define PART_A_SORT_7_LABEL_STRING1 1100
#define PART_A_SORT_7_LABEL_STRING2 3200
#define PART_A_SORT_7_LABEL_STRING3 2300
#define PART_A_SORT_7_LABEL_STRING4 1400
#define PART_A_SORT_7_LABEL_STRING5 6500
so, I tried to make a Macro defines another macros like this.
#define MY_DEFINE(PART_SORT, C1, C2, C3, C4, C5) \
#define PART_SORT##_LABEL_STRING1 C1 \
#define PART_SORT##_LABEL_STRING2 C2 \
#define PART_SORT##_LABEL_STRING3 C3 \
#define PART_SORT##_LABEL_STRING4 C4 \
#define PART_SORT##_LABEL_STRING5 C5
yeah, I thought the first ugly, big bulk of definitions will be
compacted like this.
MY_DEFINE(PART_A_SORT_1, 100, 200, 300, 400, 500)
....
MY_DEFINE(PART_A_SORT_7, 1100, 3200, 2300, 1400, 6500)
but I found #define treats '#' and '##' special. ## concats, # makes
string.
Now I guess you know what I'm trying to do.
Is there WAY to achieve this? or
REASON why I cannot?
Reguards.