[forwarded from http://bugs.debian.org/425623]
This code:
#include <stdio.h>
int main(int argc, char *argv[])
{
void *a, *b;
printf("%d\n", a - b);
return 0;
}
will generate this warning on a 64-bit platform:
temp.c:5: warning: format %d expects type int, but argument 2 has type
long int
because a - b has type ptrdiff_t and sizeof(ptrdiff_t) == 8 on a 64-bit
platform. However, on a 32-bit platform the code will generate no warning. I
believe it should generate a warning like this on all platforms, if not by
default then with an appropriate option:
temp.c:5: warning: format %d expects type int, but argument 2 has type
ptrdiff_t
In C99, such code can use %td; the t size modifier corresponds to the
ptrdiff_t type. If the code does not want to count on c99, it could cast the
difference to a long and use %ld.
--
Summary: Option to warn on printf of ptrdiff_t without t size
modifier
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: debian-gcc at lists dot debian dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34941