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

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

问题:

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下是不能同时使用宏替换的。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航