How to stringify a string which contains a comma?

前端 未结 2 900
生来不讨喜
生来不讨喜 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:51

    __VA_ARGS__ must be in each call:

    #define _STRINGIZE(...) #__VA_ARGS__
    #define STRINGIZE(...) _STRINGIZE(__VA_ARGS__)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题