Concatenate int to string using C Preprocessor

前端 未结 3 1224
离开以前
离开以前 2020-11-28 22:25

I\'m trying to figure out how I can concatenate a #define\'d int to a #define\'d string using the C Preprocessor. My compiler is

3条回答
  •  孤街浪徒
    2020-11-28 22:52

    A working way is to write MY_FILE as a parametric macro:

    #define MY_FILE(x,y) "/home..." #x #y
    

    EDIT: As noted by "Lindydancer", this solution doesn't expand macros in arguments. A more general solution is:

    #define MY_FILE_(x,y) "/home..." #x #y
    #define MY_FILE(x,y) MY_FILE_(x,y)
    

提交回复
热议问题