NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Pragmas in C++

From Texas Instruments Wiki
Jump to: navigation, search

The Big Difference vs C[edit]

In C, pragmas specifically name the entity they operate on, and thus can appear some distance away from where that entity is defined. For example ...

<syntaxhighlight lang="cpp">

  1. pragma CODE_SECTION(fxn, "mysect");

// many lines later ...

void fxn(int arg) { ... // fxn is finally defined </syntaxhighlight>

In C++, the pragmas are positional. They do not name the entity they operate on. They always operate on the next entity defined after the pragma. The above example, in C++, must be written ...

<syntaxhighlight lang="cpp">

  1. pragma CODE_SECTION("mysect") // NO semi-colon!

// The affected function must be the very next entity void fxn(int arg) { ... </syntaxhighlight>

Hide It in a Macro[edit]

If you need your code to work whether it is compiled as either C or C++ code, a macro like this is useful.

<syntaxhighlight lang="cpp">

  1. define PRAGMA(x) _Pragma(#x)
  2. ifdef __cplusplus
  3. define CSPRAGMA(f,s) PRAGMA(CODE_SECTION(s))
  4. else
  5. define CSPRAGMA(f,s) PRAGMA(CODE_SECTION(f, s))
  6. endif

CSPRAGMA(fxn, "mysect") // NO semi-colon void fxn(int arg) { ... </syntaxhighlight>

This macro is, of course, positional when used in C++. So, for the code to be portable, the macro must be viewed as positional even when used in C code.

Pragmas You Can Understand is a good article on wrapping pragmas in a macro, via _Pragma, for better portability.

E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Pragmas in C++ here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Pragmas in C++ here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article Pragmas in C++ here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article Pragmas in C++ here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article Pragmas in C++ here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Pragmas in C++ here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Pragmas in C++ here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article Pragmas in C++ here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article Pragmas in C++ here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity