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/TMS320F28069: Extern "C" (Flash_CallbackPtr *) problem

Part Number: TMS320F28069
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: TI C/C++ Compiler

Hello everyone.

I've uncovered one of my old projects for Piccolo, that was made using 6.2.0 Compiler. Now I have 16.12.0 STS compiler. But the project doesn't compile.

The compiler gives error on a function pointer "extern void (*Flash_CallbackPtr) (void);" from "F2806x_BootVars.h". It's surrounded with "extern "C" {}".

This function is also in "F2806x_GlobalVariableDefs.c" - void (*Flash_CallbackPtr) (void);

So the comipler complains on this: "../src/F2806x_GlobalVariableDefs.c", line 474: error #148: declaration is incompatible with "void (*Flash_CallbackPtr)() C" (declared at line 31 of "C:\WorkSpaces\ProjectsGit\ServoPiccolo69\include\F2806x_BootVars.h")

Look's like this causes an error on all compilers above 6.2.0 - i've tried 16.9.1, 16.6.0, 6.4.12.

The project includes only of TI files - from ControlSUITE "device_support" folder: headers and source-files for peripherals and system control.

Help me with this problem, please.

  • Small addition: i have "Treat C-files as C++" option turned on.
  • One more update - link to a project, that has this bug.

    It's made up of controlSUITE default files for F28069 device. Source and include files are placed into folders, that have names corresponding to paths in controlSUITE folder.

    Project has option "Treat C files as C++" turned on in project properties "CCS Build - C2000 Compiler - Advanced Options - Language Options"

    Also I had to fix some files:

    • "device_supportl.f2806x.v151.F2806x_common.source/F2806x_PieVect.c" in function "void InitPieVectTable(void)". Compiler didn't like initialization of "Uint32*" variable with "void*" type;
    • "device_supportl.f2806x.v151.F2806x_common.source/F2806x_SysCtrl.c" - copmiler complained about bad pragma "#pragma CODE_SECTION(InitFlash,"secureRamFuncs");" and indeed it was uncompatible with C++ pragma style.


    yadi.sk/.../N5QzgB3G3E6uGr

  • It is very likely that you ought not to have the "Treat C files as C++" option turned on when compiling those files. It is likely that they were meant to be compiled as C code. My evidence for this is that F2806x_BootVars.h declares the function as an extern "C" function when the header file is included in C++ code. You should disable the "Treat C files as C++" option at the project level and instead only turn it on for files which must be compiled as C++ files. You should seriously consider naming your C files with the .cpp extension so that you do not need the option at all.
  • Well, it's not so easy.
    I need that flag for my real project, because the project contains "cpp" files. In my previous post there was just an example of the problem. I can't share the original project, because of some kind of copyright =)
  • If the file is already named with the .cpp extension, the compiler will automatically recognize it as a C++ file without the need for the option.
  • We have lots of warnings in out projects without this flag.
    I guess, we are doing something wrong, but it was working for years with old compilers. It could be bug of the old compilers, though =)
    So in out projects we mix C and C++, so we have some headers with classes. Without aforementioned flag, we get errors like "identifier "class" is not undefined".
    Here is the example: yadi.sk/.../N5QzgB3G3E6uGr
    P.S.: I'm really not a specialist in C++, but have to deal with some projects of our team, that have C++ =(
  • It sounds like you're including C++ headers in your C files. That won't work. It might be easiest for you to switch over to C++ (as you did) by enabling the "Treat C-files as C++" option and either remove all 'extern "C"' blocks or rigorously apply extern "C" to all the definitions in your "C" files.

    See e.g. here for an explanation of what extern "C" does: www.drdobbs.com/.../184403437

  • Thank you for the advice.

    I'm using second way now - "rigorously apply extern "C" to all the definitions in your "C" files". It helps, but i get warning in "F2806x_GlobalVariableDefs.c"

    #ifdef __cplusplus
    #pragma DATA_SECTION("FlashCallbackVar");
    #else
    #pragma DATA_SECTION(Flash_CallbackPtr, "FlashCallbackVar");
    #endif
    extern "C" void (*Flash_CallbackPtr) (void);
    

    It says: "../src/F2806x_GlobalVariableDefs.c", line 470: warning #1373-D: pragma DATA_SECTION can only be applied to definitions of symbols that have static storage, not "Flash_CallbackPtr" (declared at line 31 of "C:\WorkSpaces\ProjectsGit\ServoPiccolo69\include\F2806x_BootVars.h"). Anyway, looks like the program is running OK.

    Still, I think it's ridicolous, that there was no such problem with older compiler. And also it's strange, that the problem occurs in standard TI files.

  • You need to enclose the definitions in braces, otherwise they are merely declarations:

    #ifdef __cplusplus // NB: now that you treat everything as C++, I'd do away with the #ifdef __cplusplus conditionals
    #pragma DATA_SECTION("FlashCallbackVar");
    extern "C" 
    {
    #else
    #pragma DATA_SECTION(Flash_CallbackPtr, "FlashCallbackVar");
    #endif
    void (*Flash_CallbackPtr) (void);
    #ifdef __cplusplus
    }
    #endif

  • This leads to "error #612: this kind of pragma may not be used here" =(
  • Ah, sorry, of course you should put the pragma behind the opening brace...

    #ifdef __cplusplus // NB: now that you treat everything as C++, I'd do away with the #ifdef __cplusplus conditionals
    extern "C" 
    {
    #pragma DATA_SECTION("FlashCallbackVar");
    #else
    #pragma DATA_SECTION(Flash_CallbackPtr, "FlashCallbackVar");
    #endif
    void (*Flash_CallbackPtr) (void);
    #ifdef __cplusplus
    }
    #endif

  • Yeah, that worked. Thank you =)