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.

Problem with the for loop

Hi,

I have a problem when using CCS. Here is a simple for loop as a part of my project.

 

for(int i = 0; i <= index/2;i++)

{

temp = buffer[i];

buffer[i] = buffer[index-i];

buffer[index-i] = temp;

}

 

But when I build the project, there are two error appear. Both errors were pointed to the first line.

1. expected an expression

2. identifier "i" is undefined

Why is that happening?

Thanks.

 

Shan

  • Defining a variable within a "for" statement is a feature of C++, not of C (or at least not of the C89 which TI supports).

    If your source file ends in .c, it will be compiled as a C file, unless you use an option to say otherwise.  Either define i separately at the beginning of the function, or rename your file to end in .cpp, or check the option (whose name I don't remember) to compile as C++.

  • Hello guys,

    i have exactly the same problem. Code Composer cannot handle C99 - ish for loops. This happened after I have created a new workspace and added existing C and header files in it (this was neccesary because CC had problems opening the Workspace before). Then this problem occure, before that everything was working fine.

    It has to be something with an compiler flag. Does anyone has a hint how to set the C99 flag on the Project properties?

     

    Regards

    Bernhard