printf: Ambiguous warning

Rene Kita mail@rkta.de
Tue Mar 16 10:20:05 GMT 2021


(Please keep me CC'd, I'm not subscribe to the list)

Here is a minimal example:
#include <stdio.h>

int
main()
{
  unsigned short n;
  unsigned short *p;
  p = &n;

  printf("p: %hn\n", p);
}


% gcc -Wall -Wpedantic main.c
main.c: In function 'main':
main.c:10:16: warning: format '%hn' expects argument of type 'short int *', but argument 2 has type 'short unsigned int *' [-Wformat=]
   10 |   printf("p: %hn\n", p);
      |              ~~^     ~
      |                |     |
      |                |     short unsigned int *
      |                short int *
      |              %hn

The warning for line 10 suggests to use '%hn' as format specifier which
is already used and the wrong one. AFAIK the correct format specifier
would be '%p' here.

I didn't not find a bug report for this. Is this a known problem? Should
I file a bug report for this?


% gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/kt/bin/gcc-latest/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-werror
--enable-languages=c,c++,go --disable-bootstrap --disable-nls
--enable-threads=posix --enable-default-pie --enable-checking=release
--program-suffix=-latest --prefix=/home/kt/bin/gcc-latest
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.0.1 20210315 (experimental) (GCC) 


More information about the Gcc mailing list