help on inconsistent printf() warning from gcc

Eric Blake
Fri Oct 31 22:25:00 GMT 2014

On 10/31/2014 01:13 PM, Craig Howland wrote:
> On 10/31/2014 02:49 PM, Joel Sherrill wrote:
>> Hi
>> ...
>> 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.
> Not that this changes the behavior, but the test cases are labeled
> backwards.  After applying the wchar_t-to win_t correction that Myers
> points out, the correct format is %lc (per C99), while %C is non-standard.

Wrong.  Per POSIX, %C is identical to C99's %lc:

However, your examples are also doing it wrong.  Re-read the %lc

    If an l (ell) qualifier is present, the wint_t argument shall be
converted as if by an ls conversion specification with no precision and
an argument that points to a two-element array of type wchar_t, the
first element of which contains the wint_t argument to the ls conversion
specification and the second element contains a null wide character.

You weren't passing a NUL-terminated wint_t array:

  wchar_t wc= L'a';
  printf("%C", wc);

Correct usage would look more like:

  wint_t wc[2] = L"a";
  printf("%C", wc);

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Newlib mailing list