SLAU132V October 2004 – February 2020
The MSP430 C/C++ compiler supports the C99 preprocessor _Pragma() operator. This preprocessor operator is similar to #pragma directives. However, _Pragma can be used in preprocessing macros (#defines).
The syntax of the operator is:
_Pragma ("string_literal"); |
The argument string_literal is interpreted in the same way the tokens following a #pragma directive are processed. The string_literal must be enclosed in quotes. A quotation mark that is part of the string_literal must be preceded by a backward slash.
You can use the _Pragma operator to express #pragma directives in macros. For example, the DATA_SECTION syntax:
#pragma DATA_SECTION(func,"section")
Is represented by the _Pragma() operator syntax:
_Pragma ("DATA_SECTION(func,\"section\")")
The following code illustrates using _Pragma to specify the DATA_SECTION pragma in a macro:
...
#define EMIT_PRAGMA(x) _Pragma(#x)
#define COLLECT_DATA(var) EMIT_PRAGMA(DATA_SECTION(var,"mysection"))
COLLECT_DATA(x)
int x;
...
The EMIT_PRAGMA macro is needed to properly expand the quotes that are required to surround the section argument to the DATA_SECTION pragma.