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.

TMS320F280049C: CCS mixing C and C++ files issue

Part Number: TMS320F280049C

Hi there,

we decided to write our project in C++ but to avoid the complicated and less efficient approach of using ISR in C++ we wanted to have the ISRs in a C file hence, mixing C++ and C files. So far everything compiled well but now where I'm adding my isr.c file it seems that C++ tries to compile everythin as c isntead of C++.

The error I get is: "identifier "class" is undefined" pointing to the line in the C++ header file which declares the Class. In the files properties the files type is "C Header File". I assume this should be "C++ Header File"? 
The error only occurs if I have a *.c file in the projects src folder. If I remove my isr.c file the projects builds fine.


Any suggestions on what I could do to make CCS understand which files are C and which are C++? If I add the -fg compiler option (compile all as C++) the project can't be compiled due to the several drivers I'm using.  

Thanks,

Lennart

  • Hello Lennart,

    It is the file name extension that determines if the file will be compiled as C or C++. For example, *.c will be compiled as a C file. *.cpp will be compiled as C++. You can see the full list in the preferences under 'Window -> Preferences':

    Note that you may need to "Show advanced settings" via the option in the lower left corner.

    What are the file name extensions for your C and C++ files?

    Thanks

    ki

  • Hi Ki,

    the extensions are *.c and *.cpp. The problem however is in a header file (*.h)!
    It seems to me that once a *.c file is included in the project, all header files are treated as C and not C++ code.

    Regards,

    Lennart

  • I see. Thank you for the explanation. I tried to reproduce the issue but was not successful. I had a mix of C and C++ files and some *.h files with C++ content. It builds successfully. Perhaps you can provide a small reproducible test case that reproduces the issue?

  • Hi Ki,

    thanks for taking the time to try to reproduce. I think the issue is that I included a *.cpp's header file in the *.c file and tried to use a class member function in the ISR written in C. I just didn't know any better 12 hours ago... now I do. I will have to rethink the approach I was going for to get a better crossing between C and C++ using the necessary wrappers.

  • Ah ok. Thank you for the explanation. Please keep us posted on your progress.

    Thanks

    ki