龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

gcc支持在#pragma语句中使用宏替换吗

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
问题: gcc编译器似乎对宏编译指令不支持宏替换,比如: #define PACK1 pack(1) #pragma PACK1 回答: gcc 不支持#pragma行上的宏替换,参见: info gcc 5.25 Declaring Attributes of Functions ... Some people obje

  问题:

  

gcc编译器似乎对宏编译指令不支持宏替换,比如:

  

#define PACK1 pack(1)

  

#pragma PACK1

  

  

  

回答:

  

gcc 不支持#pragma行上的宏替换,参见:

  

  

info gcc

  

5.25 Declaring Attributes of Functions

  

...

  

Some people object to the `__attribute__' feature, suggesting that

  

ISO C's `#pragma' should be used instead. At the time `__attribute__'

  

was designed, there were two reasons for not doing this.

  

  

1. It is impossible to generate `#pragma' commands from a macro.

  

  

2. There is no telling what the same `#pragma' might mean in another

  

compiler.

  

  

...

  

  

如此说来,使用#pragma在不同的编译器之间很难保证兼容性,

  

假如非要用的话,至少在gcc下是不能同时使用宏替换的。

  

精彩图集

赞助商链接