How to get warnings of incorrect string formatting (C++)

后端 未结 1 595
清歌不尽
清歌不尽 2021-02-05 12:40

apologies in advance if i use poor terminology.

when i compile a C++ app under gdb and use printf() it gives me awesome warnings relating to the consistency of the forma

相关标签:
1条回答
  • 2021-02-05 13:16

    You can do stuff like this for your own printf-like functions (as well as for scanf/strftime/strfmon-like functions):

    #define PRINTF_FORMAT_CHECK(format_index, args_index) __attribute__ ((__format__(printf, format_index, args_index)))
    
    void my_printf(const char *fmt, ...) PRINTF_FORMAT_CHECK(1, 2);
    

    See the gcc manual for further details.

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