This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: inconsistent printf() warning printing size_t
- From: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- To: Craig Howland <howland at LGSInnovations dot com>, "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Fri, 13 Mar 2015 13:33:13 -0500
- Subject: Re: inconsistent printf() warning printing size_t
- Authentication-results: sourceware.org; auth=none
- References: <55032873 dot 8060606 at oarcorp dot com> <55032A7D dot 4030505 at LGSInnovations dot com>
Thanks. I am trying to whittle down the remaining warnings
in the RTEMS source base and now are down to the ones
folks (including myself) have ignored because they are
only showing up on a subset of targets.
Hopefully this will explain more of the printf() format
warnings.
--joel
On 3/13/2015 1:20 PM, Craig Howland wrote:
> 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
>> ===================
>>
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985