public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* printf: Ambiguous warning
@ 2021-03-16 10:20 Rene Kita
  2021-03-16 10:26 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Rene Kita @ 2021-03-16 10:20 UTC (permalink / raw)
  To: gcc; +Cc: mail

(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) 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-16 11:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 10:20 printf: Ambiguous warning Rene Kita
2021-03-16 10:26 ` Jakub Jelinek
2021-03-16 10:46   ` Rene Kita
2021-03-16 11:23     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).