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.

_pragma usage



Hi there,

I use pragmas for assinging variables to data sections and  recently realised that `_Pragma()` would be more standards compliant than `#pragma `.

However, after reading the TI advice on `_pragma` usage at http://processors.wiki.ti.com/index.php/Pragmas_You_Can_Understand I'm not sure I've correctly understood their use with regard to the string literal operand.

Would the following be correct in C on C2000?

static struct  FOO_Obj foo = {0U};
#ifndef TEST
_Pragma ("DATA_SECTION (foo, \"FOO_Section\")");
#endif

Thanks, T

  • Toby Mole said:
    Would the following be correct in C on C2000?

    It is correct in the sense that it causes the variable foo to be placed in a section named FOO_Section, instead of the default section .ebss.  But it is not typical coding practice.

    Toby Mole said:
    `_Pragma()` would be more standards compliant than `#pragma `.

    That is not accurate.  Both forms are compliant with the standards.  In practice, use the simplest method to achieve the goal.  In this case, prefer #pragma over _Pragma, because it is simpler.  The _Pragma operator is used only when you need to write a preprocessor macro that uses a pragma.  Such a macro cannot use #pragma, but it can use _Pragma.

    Thanks and regards,

    -George

  • Hi George,

    Thanks for the reply.

    I see I've misunderstood my source (not the linked TI wiki page) that said that #pragma xxxx was compiler dependent, they were referring to the xxxx rather than the #pragma (vis-à-vis standard C) I guess?

    Ta, T