宏定义转换为字符串

来源:互联网 发布:p2p h.264网络摄像机 编辑:程序博客网 时间:2024/05/16 10:46


#if !defined(SW_VER_MAJOR)
#define SW_VER_MAJOR 6
#endif

#if !defined(SW_VER_MINOR)
#define SW_VER_MINOR 15
#endif

#if !defined(SW_VER_REVISION)
#define SW_VER_REVISION 1
#endif

#if !defined(SW_VER_BUILD_ID)
#define SW_VER_BUILD_ID 14
#endif


#define __STR__(s)     #s
#define MACRO2STR(s)      __STR__(s)          // 转换宏
#define __VER_CONS__(a,b,c,d)  a##.##b##.##c##.##d
#define VER_CONS(a,b,c,d)   __VER_CONS__(a,b,c,d)       // 转换宏


char *ver = MACRO2STR(VER_CONS(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_REVISION,SW_VER_BUILD_ID));

printf("\nver=%s\n",ver);



0 0