This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/LAUNCHXL-F28379D: Bug with stdlib.h- atof function

Part Number: LAUNCHXL-F28379D


Tool/software: TI C/C++ Compiler

Hi,

I am currently using CCS-8.2 to run a code on launchxl f28379d. I have a code which accesses atof function. The function runs fine when calledwithin an infinite loop-for(;;)

However, If I use "if" statement with a volatile variable, it stops at:

#ifdef _INLINE

static __inline double atof(const char *_st)
{
  return strtod(_st, (char **)0);
}

#endif  /* _INLINE */

Can anyone give me a solution to it?

  • What error do you get, and you lost me between "if statement with volatile variable" and "code which access atof() function".
  • I changed the optimization level and it works.
  • That's scary.
    Let me channel my internal George Mock.
    I think you should submit a compiler test case for each optimization level so that that George can see what is happening and file a compiler bug.
  • Okay, I will do that. Thank you for helping me out.

  • I don't understand you mean by ...

    silsio said:
    If I use "if" statement with a volatile variable, it stops at:

    Please explain what you mean by "stops".  What stopped?  Exactly how do you know it stopped?  What are you looking at?

    Thanks and regards,

    -George

  • After I debugged and ran the code, I intitally hit "resume" and I couldn't see any output. when i hit "pause", it stopped at the given part of the code. That's what i meant by stop here.
  • I'm sorry, but I'm still confused.  Every time you hit pause, the code is stopped in the same place?  Do you think something has gone wrong and caused an unexpected infinite loop?

    Thanks and regards,

    -George

  • The code only works when the optimization is set to off. Anything other than that, it doesn't work.
  • Unfortunately, your description is still too vague to work with.  Please be more precise.  When the code fails, how do you know?  Exactly what do you look at?

    Thanks and regards,

    -George

  • George Mock said:

      When the code fails, how do you know? Exactly what do you look at?

    I have a code which is supposed to read the output from an imu via SCI communication. The IMU sends out output as :

    <-12.43>

    <-12.345>

    .

    .

    .

    So, I use a code which reads this from SCI's buffer and converts into a float value when chars are between '<' and '>'. I do the char to float conversion using atof function. I have allotted a variable to this char such that it can be viewed in the "expressions" section. There was  working code which gives me the output in the "expressions" section for the variable I have allotted. This working code gives me output only when SCI buffer is read continuously in an infinity loop. I dint want to read it in an infinity loop but give control to a different function which calls it once in a while. So what this new code does is, it waits for a varialbe to go high and once it is high, it starts reading SCI buffer for a while and stops. 

    However, when i run the code, it shows no output(the variable in "expressions" shows no output) and when i pause it, it always ends up at the same loop mentioned in my first comment.  When i changed the optimization level to off, I see output (the variable in "expressions" shows output) and doesnt go into any loop.

    This is the best possible explanation i can give you about what's happening.

  • I don't understand everything in your explanation.  But I'm pretty sure you have failed to use the keyword volatile on one more more variables.  To understand volatile and when to use it, please see this article on it.

    Thanks and regards,

    -George

  • silsio said:

    use "if" statement with a volatile variable, it stops at:

    #ifdef _INLINE
    
    static __inline double atof(const char *_st)
    {
      return strtod(_st, (char **)0);
    }
    
    #endif  /* _INLINE */

    As I have informed before, I have used volatile keyword. 

  • I apologize for the delay.

    silsio said:
    I have allotted a variable to this char such that it can be viewed in the "expressions" section.

    Consider the possibility that, due to compiler optimization, this variable no longer exists.  Try making this variable volatile.  

    If that doesn't work, then I'm afraid you will have to debug the code at assembly level to work out the problem.  To understand compiler generated assembly better, add the build option --src_interlist then inspect the resulting .asm file.

    Thanks and regards,

    -George

  • I suppose you have been forced to attempt to debug this problem at assembly level.  I'm sorry about that.  Please tell us about the progress you have made.

    Thanks and regards,

    -George

  • Since it has been a while, I presume you have resolved your problem.  I'd appreciate hearing how you resolved it.

    Thanks and regards,

    -George