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.

casting a floating point constant to integer for use in defining an array

Other Parts Discussed in Thread: CCSTUDIO

Greetings, dumb question here.

First of all, the setup:

ccstudio 4.1.3, building a static lib for a C6748 DSP with CGT 6.1.9

Here is some code that generates a compiler error: (I've simplified it for discretion purposes, but this simple code still generates the error)

#define NUM1      9.1f

#define NUM2      3.0f

#define A_NUMBER (Uint32)(NUM1/NUM2)

Then sometime later I try to declare an array:

Uint32 myArray[A_NUMBER];

And the compiler gives the error that the expression ( int myArray[A_NUMBER] ) must have an integral type. This same code compiles just fine in MS Visual Studio. Obviously the compiler is not seeing the A_NUMBER constant as an integer value (despite the Uint32 casting) and complaining about the declaration. How do I get this to compile? Changing NUM1 and NUM2 to integers is not an option as in my real code, these constants are used in other places as float values. Thanks in advance.

  • It is the floating-point division which gets this code in trouble.   The parser is a bit flexible about allowing compile-time constant expressions where an integer constant is expected, but this is a bit too much.  You can still get the parser to accept it by using the '-pr' (relaxed) or '--gcc' options.

  • The '-pr' (relaxed) option 'appears' to have worked. The weird thing is that although the library was built, I have 14 errors in the "problems" window.  These error messages are very cryptic:

    /dev/myProject/DSP_libProj/c6748_nrbuild/src/Algorithm/Intface" --diag_warning=225 --preproc_with_compile --preproc_dependency="src/Algorithm/Core/generateNRSigs.pp" --obj_directory="src/Algorithm/Core"  "../src/Algorithm/Core/generateNRSigs.cpp"               c6748_nrbuild    line 0    1299271822815 839

    I have no clue what this means as an error, and there is nothing in the console window output that indicated any kind of error.

    Thanks again

  • That is mighty cryptic.  Are you sure that's the entire text of the error?   Most of that snippet is command-line options, which don't normally show up in the error text.

  • yep, unfortunately that's it. I was thinking initially I had some path problem, but then I rather think that build wouldn't have completed. Since it seems to mention the .pp (preprocessed) file a couple of times, could it be somehow related to that? I notice that when I do a "clean", I still have .pp files with yesterday's date.

  • This might be a bug in the CCS IDE. If I understand correctly, the console view does not show any errors and the build completes successfully, but the Problems view shows these messages, correct? I saw a similar issue a while ago, but the scenario was different. In that case too, CCS would successfully complete the build but report error in the Problems view, but in a very specific case. You can view the details on this bug SDSCM00039251 using the SDOWP link in my signature.

    The root cause here might be different though. Are you able to provide us with your project so we can duplicate the issue and fix it for a future release?

     

  • Unfortunately I'm not permitted to post this project. When I have some time, I will attempt to strip the project down such that I can still recreate the issue and be able to post it.

    Thanks again for your help