SourceForge has been redesigned. Learn more.

#319 printf() is broken for width modifiers

Johan Knol

E.g. "%9d" or "%-9d" does weird things, e.g. for 1, 2,
3, or 4 number digits.
I don't have time to fix it now ("%09d" works :), so
feel free to tackle this (should be easy) one. If no
one does, this is just a reminder to myself.


  • Bernhard Held

    Bernhard Held - 2002-03-30

    Logged In: YES

    These are 2 bugs: left_justify is fixed in vprintf.c 1.18.
    right_justify is a compiler-bug.

  • Marcos Augusto Stemmer

    Logged In: YES

    I also noticed that the normal printf even without type modifiers.
    There are many implementations of printf included in the sdcc
    2.3 package, some of them quite buggy.
    One that works OK as far as i tested is printf_fast. So i use
    to place a
    #define printf printf_fast
    at the begining of the program or in the header file.

  • Bernhard Held

    Bernhard Held - 2003-05-10
    • labels: 410691 --> Live range problems
  • Bernhard Held

    Bernhard Held - 2003-09-29

    Logged In: YES

    From sdcc-devel:
    FROM: Johan Knol
    DATE: 03/31/2002 01:27:08
    SUBJECT: RE: [sdcc-devel] [ sdcc-Bugs-536787 ] printf() is
    broken for width modifiers
    > The problem is within the loop below. If you declare the
    > variables width or
    > length as volatile, the output is ok.
    > Bernhard
    > ; vprintf.c:568: while ( width > length+1 )

    > mov r3,a ; BUG! r3 is destroyed, which should hold
    > ; the loop-invariant (length +1)

    That's right, the iTemp with the invariant xpression "length+1"
    is moved to the preheader of the block, but it's life-range
    should be extended to the end of the loop. I don't know how
    to do that. Sandeep?


  • Nobody/Anonymous

    Logged In: NO

    i mailed a patch on the dev mailinglist, that should fix
    these liverange problems. It fixes at least the bug 519583.

    Klaus Flittner

  • Maarten Brock

    Maarten Brock - 2004-03-09

    Logged In: YES

    I tried to reproduce this problem, but was not able to. Maybe
    this bug is fixed by now and should be closed?

  • Bernhard Held

    Bernhard Held - 2004-03-09

    Logged In: YES

    Thanks Klaus for the great fix, thanks Maarten for re-

  • Bernhard Held

    Bernhard Held - 2004-03-09
    • milestone: --> fixed
    • assigned_to: nobody --> kflittner
    • status: open --> closed-fixed

Log in to post a comment.