am7xxx: fix C99 conformance for printf & co. when compiling with MinGW
authorAntonio Ospite <ao2@ao2.it>
Tue, 27 Feb 2018 16:03:36 +0000 (17:03 +0100)
committerAntonio Ospite <ao2@ao2.it>
Tue, 27 Feb 2018 16:20:06 +0000 (17:20 +0100)
commitbbebd199987581ee6f344c89bfb02237dc0ab0bd
tree0c83f4f2ce036fdfe7337b55352767ef58c4acb2
parentbdf46231090f97e1d941b5b24078fc40140738c4
am7xxx: fix C99 conformance for printf & co. when compiling with MinGW

C99 format specifiers like "%hhd" are used with log_message() but MinGW
(and Windows) does not really supports them, so the compiler suggests to
use the "gnu_printf" attribute for the function.

However "gnu_printf"is not available on clang so it's not an option,
a better alternative is the solution suggested by MinGW at
https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/

The change fixes the following warnings when compiling with MinGW:

.../libam7xxx/src/am7xxx.c: In function ‘log_message’:
.../libam7xxx/src/am7xxx.c:647:3: warning: function ‘log_message’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
   vfprintf(stderr, fmt, ap);
   ^~~~~~~~
.../libam7xxx/src/am7xxx.c: In function ‘open_device’:
.../libam7xxx/src/am7xxx.c:772:15: warning: unknown conversion type character ‘h’ in format [-Wformat=]
    debug(ctx, "Cannot set configuration %hhu\n",
               ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:772:15: warning: too many arguments for format [-Wformat-extra-args]
    debug(ctx, "Cannot set configuration %hhu\n",
               ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:785:14: warning: unknown conversion type character ‘h’ in format [-Wformat=]
   debug(ctx, "Cannot claim interface %hhu\n",
              ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:785:14: warning: too many arguments for format [-Wformat-extra-args]
   debug(ctx, "Cannot claim interface %hhu\n",
              ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:803:14: warning: unknown conversion type character ‘h’ in format [-Wformat=]
   debug(ctx, "libusb configuration changed (expected: %hhu, current: %d)\n",
              ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
.../libam7xxx/src/am7xxx.c:803:14: warning: too many arguments for format [-Wformat-extra-args]
   debug(ctx, "libusb configuration changed (expected: %hhu, current: %d)\n",
              ^
.../libam7xxx/src/am7xxx.c:65:85: note: in definition of macro ‘debug’
 #define debug(ctx, ...)   log_message(ctx,  AM7XXX_LOG_DEBUG,   __func__, 0,        __VA_ARGS__)
                                                                                     ^~~~~~~~~~~
src/CMakeLists.txt
src/am7xxx.c