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.

C++ Infinite recursion in cpp_inline_math.h for 2000 tools and CCS v4.0

I have a c++ application that is utilizing the math.h library and calling fabs.  When I run this on my hardware (F28335) I found that the code was getting stuck constantly calling fabs.  Upon investigation I discovered that in the cpp_inline_math.h file, the inline fabs function calls fabsf.  However, fabsf is #defined to be fabs, thus resulting in infinite recursion. Is there some other include file I should be using when trying to use the math library functions, because I don't see how the cpp_inline_math.h file could possibly ever work?

I would appreciate it if somebody could clarify this for me.  Thanks.

 

Stephen

  • Stephen,

          I do not see this problem when I try a testcase - could you tell me the version number of the compiler tools you are using ?

    Thanks,

    Indira.

  • I am using 5.2.5.  If you look at the file itself, you will see the code problem that I am talking about.  I can't send you my code, but I can see if I can put together a test case where I can re-create the issue and send you my project and source files if you think that would help

  • Stephen V said:

    I can't send you my code, but I can see if I can put together a test case where I can re-create the issue and send you my project and source files if you think that would help

    Yes please, that would be a great help.

  • I've attached a zip file of a project I quickly put together for the eZdsp F28335 eval board. When you run it, you will see that it get stuck inside the modf function.  Let me know if it you do or do not see an error when running it yourself.

     

    Thanks,

    Stephen

     

    testProgram.zip
  • Thanks for the testcase. I can compile and build an outfile from your testcase, and it does appear to hang when I run it. I will look at this some more, but will get back to you.

    -Indira.

  • Stephen,

        To answer your question on the fabs recursion : note that at the beginning of cpp_inline_math.h, we do this :

    #define fabsf   fabs

    and then

    inline float fabs(float x)
            {       // return absolute value
            return (float)(fabsf((double)x));
            }

    fabsf occurences will be replaced by fabs, but the function called is not the same (no recursion) because of the different argument type (double).

    You can see the preprocessed version of the source by adding -ppo to your compile options :

    %>  cl6x <your compile options>  -ppo  testcase.cpp

    will produce a "testcase.pp", which will include all required source from the include files.

    Your testcase when built and run hangs in the below loop :

          while(SysCtrlRegs.PLLSTS.bit.PLLLOCKS != 1)  // DSP2833x_SysCtrl.c:192
          {
                  // Uncomment to service the watchdog
               // ServiceDog();
          }

    Once I uncomment the call to ServiceDog(), the program exits this loop and runs to completion - see output below  (I put in a few printf in addition to yours):

    At beginning

    In SysCtrl

    After InitSysCtrl

    After InitPieCtrl

    After InitPieVectTable

    Finished it!

    val: 2

     

    Thanks,

    Indira.