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.

portable alternative to #pragma DATA_SECTION and CODE_SECTION

Hi all,

is there an alternative to the #pragma DATA_SECTION and CODE_SECTION?

These are very handy for allocating single variables and functions to special memory sections, but highly non-portable.

I guess there is actually no alternative, but is TI thinking about an alternative that is more portable - and can be enabled or disabled at one centralized place via #ifdef instead of #ifdefs around each #pragma?

  • Okay, I finally found a portable alternative here http://tiexpressdsp.com/index.php/Pragmas_in_C%2B%2B and especially here http://tiexpressdsp.com/index.php/Pragmas_You_Can_Understand.

    It is done via _Pragma which was introduced in C99 and is supported in many TI compilers.

    Hopefully this is also supported on the compiler that you want to port to...

    I implemented the portable pragma as follows:

    #ifdef __TMS320C2000__
    // TI C2000 compiler knows the pragmas
    #define PRAGMA(x) _Pragma(#x)
    #define VAR_IN_SECTION(var, section) PRAGMA(DATA_SECTION(var, section))
    #else
    // for any other compiler, the pragmas are ignored
    #define VAR_IN_SECTION(var, section)
    #endif

    Instead of

    #pragma DATA_SECTION(myvar,".bss")

    You write portable:

    VAR_IN_SECTION(myvar,".bss")