[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#217360: gcc-3.2: meaningless warning for %p in format strings



Falk Hueffner wrote:
Jason Kraftcheck <kraftche@cae.wisc.edu> writes:


If the following is compiled with the options -Wall -pedantic-errors :
 #include <stdio.h>
 int main( )
 {
   int i;
   printf("%p\n", &i );
   return 0;
 }

gcc emits the following:
 voidptr.c: In function `main':
 voidptr.c:5: warning: void format, different type arg (arg 2)

This warning is meaningless.  The type of the pointer doesn't matter
for printf to write out the address.


According to the C standard, it does. And you specifically asked for
gcc to be pedantic.


The C standard says there's a difference between printing a void* and a int* (or any other type)? How can a pointer passed through a var-args list be anything but a void*? The C standard may say that %p prints a void*, but isn't any pointer passed through a var-args a void*?

An implicit cast to a void* doesn't generate a warning under other circumstances. Neither do other implicit casts in var-args lists. The following compiled with '-Wall -pedantic-errors" does not result in any warnings:

  int main()
  {
    float f;
    memset( &f, 0, sizeof(f));  /* implicit cast to void* */
    printf("%f\n", f);          /* promotion from float to double */
    return 0;
  }






Reply to: