#define #pragma 的问题
我对 C 中的#define 有疑问 我正在使用带有 IAR EW 5.10 的 MSP430F5418 我有一个名为 location 的编译指示,它将把下一个声明变量放到指定的段中。 在下面的示例中,a 将放入名为 myseg 的段中,而 b 则不会。
#pragma location="myseg" static const char a[] = "amma"; static const char b[] = "amrita";
我有很多这样的常数。 我想知道我是否可以做这样的事情...
#define TYPE location="myseg" \ static const char #pragma TYPE a = "amma"; #pragma TYPE b = "amrita"; .....
这样我就可以在每个变量声明之前避免 #pragma location="myseg"
。
I have a problem with the #define in C
I am using MSP430F5418 with IAR EW 5.10
I have a pragma called location which will put the next declaring variable to the specified segment.
In the below example a will put into the segment called myseg and b is not.
#pragma location="myseg" static const char a[] = "amma"; static const char b[] = "amrita";
I have a lot of constants like this.
I want to know whether I could do something like this...
#define TYPE location="myseg" \ static const char #pragma TYPE a = "amma"; #pragma TYPE b = "amrita"; .....
so that I can avoid #pragma location="myseg"
before each variable declaration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在
#define
中使用#pragma
,反之亦然。为了规避此限制,一些编译器提供了
_Pragma
运算符 (GCC、LLVM)(Visual C++ 中的__pragma
)提供与#pragma
指令相同的功能。该运算符可以在另一个宏中使用。查明您的编译器是否支持此类编译指示运算符。使用这个,你可以写:
You cannot use a
#pragma
inside a#define
, nor the other way round.To circumvent this restriction, some compilers offer a
_Pragma
operator (GCC, LLVM) (__pragma
in Visual C++) which provide the same functionality as the#pragma
directive. This operator can be used in another macro. Find out whether your compiler supports such a pragma operator.Using this, you could write: