Bug#425623: gcc-4.1: Option to warn on printf of ptrdiff_t without t size modifier
Package: gcc-4.1
Version: 4.1.2-7
Severity: wishlist
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.
- Josh Triplett
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.22-rc1 (PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages gcc-4.1 depends on:
ii binutils 2.17cvs20070426-6 The GNU assembler, linker and bina
ii cpp-4.1 4.1.2-7 The GNU C preprocessor
ii gcc-4.1-base 4.1.2-7 The GNU Compiler Collection (base
ii libc6 2.5-8 GNU C Library: Shared libraries
ii libgcc1 1:4.2-20070516-1 GCC support library
Versions of packages gcc-4.1 recommends:
ii libc6-dev 2.5-8 GNU C Library: Development Librari
ii libmudflap0-dev 4.1.2-7 GCC mudflap support libraries (dev
-- no debconf information
Reply to: