1

In C language, I'm using the following 2 macros of MAJOR_VERSION and MINOR_VERSION.

#define MAJOR_VERSION "0001"
#define MINOR_VERSION "0001"

I'd like to make a macro USER_AGENT consist of the above 2 macros of MAJOR_VERSION and MINOR_VERSION like following;

#define MAJOR_VERSION "0001"
#define MINOR_VERSION "0001"
#define USER_AGENT    "miproduct/MAJOR_VERSION.MINOR_VERSION"

But the result of the expansion of the USER_AGENT macro is unexpected that MAJOR_VERSION and MINOR_VERSION are resting not expanded.

Is there any good way to make USER_AGENT string literal from MAJOR_VERSION and MINOR_VERSION macros? Thank you for your suggestion!

Ueda Takeyuki
  • 721
  • 10
  • 26
  • 1
    `#define MAJOR_VERSION "0001" #define MINOR_VERSION "0001" #define CONNECT2(x, y) x##y #define CONNECT1(x,y) CONNECT2 (x, y) #define USER_AGENT CONNECT1(MAJOR_VERSION, MINOR_VERSION)` – Zeus Sep 10 '20 at 02:00

0 Answers0