How to stringify a string which contains a comma?

前端 未结 2 899
生来不讨喜
生来不讨喜 2021-02-10 01:15

I want to pass a version string in the compile command:

$ g++ -Wall -D VERSION=\"2013-12-03 02:15:21, commit cb060df\" -o          


        
2条回答
  •  名媛妹妹
    2021-02-10 01:58

    You can write the TOSTR_ macro to take variable arguments:

    #define TOSTR_(x...) #x
    #define STRINGIFY(x) TOSTR_(x)
    #define VERSION_STR STRINGIFY(VERSION)
    

    This code has been tested and works on Apple LLVM version 5.0.

提交回复
热议问题