Shop OBEX P1 Docs P2 Docs Learn Events
Print a Negative Integer bug in compact printf — Parallax Forums

Print a Negative Integer bug in compact printf

Christof Eb.Christof Eb. Posts: 1,237
edited 2012-09-12 12:16 in Propeller 1
Hi,
there seems to be a bug in compact printf.

#include <stdio.h>
#include <propeller.h>
#include <sys/thread.h>
#include <math.h>




int main (void)
{
int a=123, b=-456;

sleep(2);

printf("hello, world! %d %d\n", a, b);

return 0;
}


brings:
hello, world! 123 -456 without compact printf
hello, world! 123 4294966840 with compact printf

Best regards
Christof

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-09-12 09:43
    What printf are you using? There is a printf in the tiny lib, and there is simple printf specified with -Dprintf=__simple_printf

    BTW, libtiny.a compiled for LMM will not work with CMM. We've packaged the library versions that are automatically included by GCC based on the model used.
  • Christof Eb.Christof Eb. Posts: 1,237
    edited 2012-09-12 10:27
    Hi,
    I use SimpleIde (Great tool!) and just set the hook for compact printf or omit it.
    Christof
  • jazzedjazzed Posts: 11,803
    edited 2012-09-12 11:10
    Hi,
    I use SimpleIde (Great tool!) and just set the hook for compact printf or omit it.
    Christof

    I'm not able to reproduce the problem by either checking "Simple Printf" or "Tiny Lib" with version 0-8-5.
    Can you please after building the failing condition, right-click build status and select-all, then copy and paste here?

    Thanks,
    --Steve

    BTW, I'll be on line only briefly the rest of today/tonight.
  • Christof Eb.Christof Eb. Posts: 1,237
    edited 2012-09-12 11:57
    Hi, this is:

    Project Directory: C:/Users/Christof/Documents/SimpleIDE/SineBurst/

    propeller-elf-gcc.exe -o a.out -Os -mcmm -I . -Wall -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf -save-temps Test_prt.c -lm
    Test_prt.c: In function 'main':

    Test_prt.c:18:5: warning: implicit declaration of function 'sleep' [-Wimplicit-function-declaration]

    propeller-elf-objdump -h a.out
    Done. Build Succeeded!

    propeller-load.exe -I C:/propgcc/propeller-load/ -b DEMOBOARD -p COM6 a.out -r
    Propeller Version 1 on COM6
    Loading a.out to hub memory

    10180 bytes sent

    Verifying RAM ...
    OK

    ========================================================================================
    Oh, I have just seen, that if I don't select maths library, it is working and I get very much smaller code. That's funny.
  • ersmithersmith Posts: 6,095
    edited 2012-09-12 12:16
    Oh, I have just seen, that if I don't select maths library, it is working and I get very much smaller code. That's funny.

    Thanks Christof, that was just the clue we need. The version of _simple_printf in the math library has floating point support and support for 64 bit integers, which is why it's bigger, and also why it isn't working -- the integer parsing code is using 64 bit integers and not checking for 32 bit negative numbers. It should be easy to fix.

    Thank you for the bug report!
    Eric
Sign In or Register to comment.