Help save net neutrality! Learn more.
Close

issues with atoi/atof on new builds

2004-10-29
2013-03-12
  • James Davis

    James Davis - 2004-10-29

    Currently I'm using 2.4 built on 10/28/2004 (have tried with one from 10/21/2004.  My current issue is that when I upgrade from an older version 2.4 on 2/23/2004 atoi & atol no longer seem to work right.
    they work right for most values, but when I run the following code, I get unexpected results.

    #include "c8051f120.h"
    #include "uart.h"
    #include "config.h"
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>

    void main()
    {
      Init_Device();
      printf(":%d:\r\n",atoi("100"));
      while(1)
      {
      }
    }

    void UART_ISR(void) interrupt 4
    {
      char tmp;
      char SFR_PAGE = SFRPAGE;
      SFRPAGE=UART0_PAGE;
      ES0=0;
      // If it's time to transmit...
      if (TI0==1)
      {
        // Clear flag
        TI0=0;
      }

      // If a char came in
      if (RI0==1)
      {
        // if the queue is not full
        if (!RX_Full())

        // Buffer the char -- otherwise drop it.
          addRX(SBUF0);  

        if (UART_LE)
        {
          tmp=SBUF0;
            SBUF0=tmp;
            while(TI0==0);
             TI0=0;
        }
       
        // clear recv flag
        RI0=0;
      }
      ES0=1;
      SFRPAGE=SFR_PAGE;
    }

    The output I get from this code is:
    :101:
    it should be:
    :100:
    I'm using --model-large --stack-auto --pack-iram
    (I have recompiled the large model libraries for this)
    it also does this when I use just the standard included small model libraries.

    Any help here? or is this an annoying bug?

     
    • James Davis

      James Davis - 2004-11-01

      Problem found.  It was a bug in the compiler (I sumbitted a bug report) that deals with (s)printf.
      adding a #define printf printf_fast to my code to use printf_fast fixes the issue for now.

       

Log in to post a comment.