inconsistent printf() warning printing size_t
Craig Howland
howland@LGSInnovations.com
Fri Mar 13 18:33:00 GMT 2015
On 03/13/2015 02:12 PM, Joel Sherrill wrote:
> Hi
>
> This code gives a warning on some targets and not on others.
> Specifically, it gives a warning where size_t is long unsigned int
> but not unsigned int. If you use %ld, it inverts when the warning
> occurs. Any suggestions on how to portably print a size_t and
> not get a warning?
>
> ==============
> #include <stdio.h>
>
> void f( size_t x)
> {
> printf( "%d\n", x );
printf("%zd\n", x);
The 'z' length modifier means the conversion specifier applies to a size_t.
> }
> ===============
>
> This script is used to do the analysis:
>
> ===================
> for t in arm-rtems4.11 avr-rtems4.11 bfin-rtems4.11 h8300-rtems4.11 \
> i386-rtems4.11 lm32-rtems4.11 m32c-rtems4.11 m32r-rtems4.11 \
> m68k-rtems4.11 mips-rtems4.11 nios2-rtems4.11 \
> powerpc-rtems4.11 sh-rtems4.11 sparc64-rtems4.11 sparc-rtems4.11 \
> v850-rtems4.11
> do
> echo === ${t}
> ${t}-gcc -dM -E - </dev/null | grep UINTPTR_TYPE
> ${t}-gcc -Wall -Wextra -c f.c
> done
> ===================
>
More information about the Newlib
mailing list