inconsistent printf() warning printing size_t

Joel Sherrill
Fri Mar 13 18:20:00 GMT 2015


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 );

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 \
  echo === ${t}
  ${t}-gcc -dM -E - </dev/null | grep UINTPTR_TYPE
  ${t}-gcc -Wall -Wextra -c f.c

Joel Sherrill, Ph.D.             Director of Research & Development        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

More information about the Newlib mailing list