#634 printf %lx %f

closed-fixed
5
2013-05-25
2003-11-13
Anonymous
No

I cannot get output of long integers and floats
from printf.

SDCC version:
mcs51/gbz80/z80/avr/ds390/pic14/pic16/TININative/xa51/ds400/hc08
2.3.5 (Oct 21 2003) (UNIX)

Example:
--------------------------------------------
#define MICROCONTROLLER_SAB80517
#include <mcs51reg.h>
#include <stdio.h>

void main() {
long a=0x10203040;
float g=1.2345;
printf("Hello %Lx %f\n",(long)a,g); // <<--- !!!!
}
----------------------------------------------
Output:
> Hello 1020 <NO FLOAT>

Should be:
> Hello 10203040 1.2345

Compile: sdcc xxx.c

Sedlak Anton <ased@cce.cz>

Discussion

  • Maarten Brock

    Maarten Brock - 2004-04-15

    Logged In: YES
    user_id=888171

    Hi,

    Tested this with SDCC 2.4.0 and %Lx prints ok.

    If I also recompile vprintf.c from the library sources with -
    DUSE_FLOATS=1 and use --model-large %f gets printed ok as
    well.

    So I see no bug here. But I think it would be nice if the
    documentation was updated on how to get printf to output
    floats.

    Greetings,
    Maarten

     
  • Paul Stoffregen

    Paul Stoffregen - 2004-08-02

    Logged In: YES
    user_id=104682

    vprintf.c can only be compiled in large memory model on
    mcs51, because it and the floating point library use a lot
    of variables.... far too much to fit into the 8051's
    internal RAM. It also consumes about 9k of code space
    (including the many float library functions needed). It's
    speed is very slow. This just isn't practical for most
    8051-based projects.

    I've been working on adding floating point support to
    printf_fast. My first pass on the code adds about 500 bytes
    and gives working float output up to 10.8 digits (+/-
    4294967295.99999998), but so far without width format
    control or nice round-off. Soon I'll add round off and
    field width code, hopefully only costing a couple hundred
    more bytes of code... So far I've managed to avoid adding
    ANY extra RAM usage (it's all in the registers and existing
    RAM used)... but the round-off will probably burn 4 bytes of
    RAM. Still a lot less than the 300-some RAM bytes used by
    vsprintf.

    I also added a couple more options to reduce code size,
    including a compact but slower integer algorithm (but still
    a lot faster than the C versions).

    I'll also add sprintf handling to printf_fast.

    When this is working, I'd like to make printf_fast the
    "default" printf for the mcs51 architecture. I believe this
    will give printf_fast the complete feature set for printf,
    for both small and large memory model, with much smaller
    code, much less CPU usage, and virtually no extra RAM consumed.

     
  • Maarten Brock

    Maarten Brock - 2004-10-05
    • labels: 101552 --> Documentation
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     
  • Maarten Brock

    Maarten Brock - 2004-10-05

    Logged In: YES
    user_id=888171

    Fixed by updating the manual on how to build printf_large.c
    so it prints floats.

     

Log in to post a comment.