Avoid warning in wrapper around printf

前端 未结 2 559
借酒劲吻你
借酒劲吻你 2020-12-19 04:51

I have an error reporting functionality in my little C library I\'m writing. I want to provide an errorf function in addition to the plain error fu

2条回答
  •  清酒与你
    2020-12-19 05:32

    If you're using GCC or one of its relatives, try an attribute on the declaration:

    void sio_errorf(const char *format, ...) __attribute__((format(printf, 1, 2)));
    

    To add the attribute to a definition, you can use this:

    __attribute__((format(printf, 1, 2)))
        static void sio_errorf(const char *format, ...) {
          ....
    

提交回复
热议问题