Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#251 printf function does not support long long

WSL
closed
Danny Smith
printf (3)
works-for-me
Known_bugs
2013-01-30
2003-01-02
Matt Ball
No

The printf function does not correctly handle long
long input parameters in the MinGW environment
(and possible other environments). The printf
function appears to attempt to handle the long
long input. However, it only pulls off one 32-bit
parameter, and does not process the second 32-bit
parameter for the long long. The next format
descriptor will typically use the upper 32-bits of
the previous long long parameter.

Here is code that could repeat this problem:

long long A = 12345678901234LL, B =
98765432109876LL;
printf("%lld, %lld\n", A, B);

GCC release: gcc (GCC) 3.2 (mingw special
20020817-1)

Mingw release: MinGW 2.0.0-3 running under
Windows NT

Discussion

  • Danny Smith
    Danny Smith
    2003-01-02

    Logged In: YES
    user_id=11494

    MSVC printf does not recognize "ll" identifier, use "I64"
    instead.
    printf("%I64d, %I64d\n", A, B);

    Danny

     
  • Matt Ball
    Matt Ball
    2003-01-02

    Logged In: YES
    user_id=679162

    Thanks for the info!
    The I64 approach will work for what I'm doing.
    However, there is still a descrepancy between gcc and
    libc. gcc does not appear to recognize the "I64" format
    specifier, and will issue a warning whenever C code
    includes it. The printf function in libc does not
    recognize the "ll" format prefix. However, gcc will not
    issue any warning if the C program uses "ll". In a future
    release we may want to resolve the differences in
    warnings issued by gcc, and what is implement for
    printf in libc. "ll" may be an ANSI C99 standard, so it
    might be worth implementing at some point.

     
  • Luke Dunstan
    Luke Dunstan
    2003-01-03

    Logged In: YES
    user_id=30442

    The C library that you are calling "libc" is the msvcrt.dll library
    provided my MS, so it is difficult to do anything to support "ll".
    Changing GCC's format checking would be easier but it is a
    fairly low priority at this stage, and I would guess that such a
    change may not be accepted for mainline GCC.

     
  • Earnie Boyd
    Earnie Boyd
    2003-01-03

    Logged In: YES
    user_id=15438

    I have someone working on an alternative library that will
    provide this capability. I have a pre-alpha version of the
    library, if you wish I can forward it to you, with the
    caveat that the name of the library may change in the final
    release. It's license is BSD with advert.

    Earnie.

     
  • Matt Ball
    Matt Ball
    2003-01-03

    Logged In: YES
    user_id=679162

    Thanks for the offer. However, for my purposes, using
    I64 should work. The confusion happened because I
    didn't realize that MinGW uses msvcrt.dll instead of libc.

     
  • Matt Ball
    Matt Ball
    2003-01-03

    • status: open --> closed-works-for-me
     
  • Earnie Boyd
    Earnie Boyd
    2013-01-30

    • labels: gcc --> printf
    • status: closed-works-for-me --> closed
    • resolution: --> works-for-me
    • category: --> Known_bugs
    • milestone: --> WSL