How should I properly use __attribute__ ((format (printf, x, y))) inside a class method in C++?

后端 未结 4 422
长发绾君心
长发绾君心 2021-01-01 10:20

I\'m trying to define a class method for debug prints that will behave like printf:

inline void debug(const char* fmt, ...) __attribute__ ((form         


        
4条回答
  •  温柔的废话
    2021-01-01 10:41

    @Chris Dodd is correct. Here's the latest gcc documentation to back it up (thanks Foxit reader for letting me mark up PDFs on Linux). Pay special attention to the part marked in green in the image below.

    Since non-static C++ methods have an implicit this argument, the arguments of such methods should be counted from two, not one, when giving values for string-index and first-to-check.

    Source: https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes (see the section titled "format (archetype, string-index, first-to-check)").

    Image (esp. see highlighting in green):

提交回复
热议问题