[Mingw-users] snprintf and %hhx format

Back to archive index
Eli Zaretskii eliz****@gnu*****
Sun May 5 23:23:48 JST 2019


The following toy program:

#include <inttypes.h>
#include <stdio.h>

int main (void)
{
  unsigned char c = 0x12;
  char buf[3];
  snprintf (buf, 3, "%02" SCNx8, c);
  puts (buf);

  return 0;
}

generates the following diagnostics:

  d:\usr\eli>gcc -Wall -o pt.exe pt.c
  pt.c: In function 'main':
  pt.c:8:21: warning: unknown conversion type character 'h' in format [-Wformat=]
     snprintf (buf, 3, "%02" SCNx8, c);
                     ^~~~~
  In file included from pt.c:1:
  d:\usr\include\inttypes.h:246:17: note: format string is defined here
    #define SCNx8 "hhx"
                    ^
  pt.c:8:21: warning: too many arguments for format [-Wformat-extra-args]
     snprintf (buf, 3, "%02" SCNx8, c);
                       ^~~~~

The warning goes away if I replace snprintf with __mingw_snprintf.  It
also goes away if I add the -fno-builtin-snprintf compiler switch.

So it looks like the __mingw_printf__ attribute fails to cause the
compiler to recognize that our snprintf does support %hh?

This is with GCC 8.2.0 and MinGW runtime 5.2.1.  I see the same
warning with GCC 7.3.0.

Am I doing something wrong?



More information about the MinGW-Users mailing list
Back to archive index