I'm trying to define a class method for debug prints that will behave like printf
:
inline void debug(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)))
When I compile with -Wformat
or -Wall
, This complains about:
error: format string argument not a string type
I recalled that a class method declaration has an implicit this
parameter, so I changed the locations of the parameters to 2, 3:
inline void debug(const char* fmt, ...) __attribute__ ((format (printf, 2, 3)))
and now it compiles, but it looks like the parameters are shifted, as if the this
parameter were being treated as part of the argument list.
How can I tell the function that this
isn't part of the string that I want to print?
this
. It's not an explicit argument, period. Just follow the GCC manual, which says that for member functions you have to add 1 to theformat
-attribute arguments. It's just an opaque rule, given to you by the vendor of a compiler extension.format
attribute specifies style of the format string, the argument location of the format string, and the argument location of the...
. The compiler then uses that information to do type checking of the...
arguments with the format string.