Bug 79616 - nonsense types in printf() format warnings
nonsense types in printf() format warnings
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-12-13 19:50 EST by David Nečas
Modified: 2007-04-18 12:49 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-03 06:58:59 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Nečas 2002-12-13 19:50:18 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021128

Description of problem:
printf() format warnings for %p (and %s and %n) format printed with -pedantic
shows bad variable types, one level of pointerness is missing.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. create a p.c file with following contents:

#include <stdio.h>
int main(void) {
  double *a, **b;
  printf("%p, %p\n", a, b);
  return 0;

2. compile it

gcc -c -Wall -pedantic p.c


Actual Results:
p.c: In function `main':
p.c:4: warning: void format, double arg (arg 2)
p.c:4: warning: void format, pointer arg (arg 3)

Expected Results:  Hard to say.  What I definitely don't expect is the `double
arg' on the second line, when arg 2 is POINTER to a double, not a double.

So expected result is anything between no warnings (when I'm printing pointers
with %p one is as good as another) and fully descriptive warning like (crazy,
but the kind of thing one expects from -pedantic):

p.c: In function `main':
p.c:4: warning: void* format, double* arg (arg 2)
p.c:4: warning: void* format, double** arg (arg 3)

Additional info:
While `double arg' corresponds to `void format' in the warning in the sense both
have one level of pointerness removed, it's confusing compared to

printf("%d", *a);

which prints

p.c:5: warning: int format, double arg (arg 2)

Both *a and a can't be double simultaneously.

The same happens for %s and %n conversion specifiers.
Comment 1 Richard Henderson 2004-10-03 06:58:59 EDT
The same bad wording persists through gcc 3.4; gcc 4.0 will generate 

z.c:4: warning: format '%p' expects type 'void *', but argument 2 has
type 'double *'
z.c:4: warning: format '%p' expects type 'void *', but argument 3 has
type 'double **'

Note You need to log in before you can comment on or make changes to this bug.