__attribute__((format(printf, 1, 2))) for MSVC?

后端 未结 4 1767
半阙折子戏
半阙折子戏 2020-12-03 17:01

With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this function takes vararg parameters that are printf format specifie

4条回答
  •  萌比男神i
    2020-12-03 17:48

    Using SAL Annotations you can use _Printf_format_string_ (as of VS2k8 or VS2k10) or __format_string (for VS2k5):

    #undef FORMAT_STRING
    #if _MSC_VER >= 1400
    # include 
    # if _MSC_VER > 1400
    #  define FORMAT_STRING(p) _Printf_format_string_ p
    # else
    #  define FORMAT_STRING(p) __format_string p
    # endif /* FORMAT_STRING */
    #else
    # define FORMAT_STRING(p) p
    #endif /* _MSC_VER */
    
    /* use /analyze or _USE_ATTRIBUTES_FOR_SAL for checking */
    extern void log_error(FORMAT_STRING(const char* format), ...);
    

提交回复
热议问题