snprintf and %hhx format

Eli Zaretskii <eliz-mXXj517/[email protected]>
Newsgroups gmane.comp.gnu.mingw.user
Message-ID <[email protected]>
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?

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.