help on inconsistent printf() warning from gcc
Joel Sherrill
joel.sherrill@oarcorp.com
Fri Oct 31 18:49:00 GMT 2014
Hi
In tracking down warnings in RTEMS, we have one which
is for a printf() format specifier on wchar_t. The code
originated in FreeBSD and the initial code we had did
have the wrong specifier. But this was flagged on a subset
of targets. When I corrected the warning, the situation
changed and some targets gave false positive.
I have attached correct and incorrect test cases. I am hoping
someone here can give me a clue as to where to look. I am
wondering if this is an inconsistency across targets in the
C library. I did file this as GCC PR63301 but it was quickly
closed as invalid. But I think the inconsistent generation of
warnings is a bug.
The test script "j" and its output are attached. Notice some
targets have no warnings, some warning on both, and mixes.
I would expect the output to be similar on *-elf targets.
Any suggestions on how to address this? I would love to
see our code be warning free on all targets.
Thanks.
--
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
-------------- next part --------------
/*
* This code uses the correct printf() format specifier and should
* not produce a warning.
*/
#include <wchar.h>
#include <stdio.h>
int main(void)
{
wchar_t wc= L'a';
printf("%C", wc);
return 0;
}
-------------- next part --------------
/*
* This code uses the incorrect printf() format specifier and should
* produce a warning.
*/
#include <wchar.h>
#include <stdio.h>
int main(void)
{
wchar_t wc= L'a';
printf("%lc", wc);
return 0;
}
-------------- next part --------------
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 moxie-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 -Wall -Wextra -c correct_wchar.c
${t}-gcc -Wall -Wextra -c incorrect_wchar.c
done
-------------- next part --------------
=== arm-rtems4.11
=== avr-rtems4.11
=== bfin-rtems4.11
=== h8300-rtems4.11
=== i386-rtems4.11
=== lm32-rtems4.11
=== m32c-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
=== m32r-rtems4.11
=== m68k-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
=== mips-rtems4.11
=== moxie-rtems4.11
=== nios2-rtems4.11
=== powerpc-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
=== sh-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
=== sparc64-rtems4.11
=== sparc-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
=== v850-rtems4.11
correct_wchar.c: In function 'main':
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%C", wc);
^
correct_wchar.c:10:3: warning: format '%C' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
incorrect_wchar.c: In function 'main':
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
printf("%lc", wc);
^
incorrect_wchar.c:10:3: warning: format '%lc' expects argument of type 'wint_t', but argument 2 has type 'wchar_t' [-Wformat=]
More information about the Newlib
mailing list