首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

_declspec关键字 在VC中如何用的

2012-02-16 
__declspec关键字 在VC中怎么用的?__declspec关键字在VC中是作怎么用的?那位大侠能告诉我这一面的细节,谢

__declspec关键字 在VC中怎么用的?
__declspec关键字   在VC中是作怎么用的?那位大侠能告诉我这一面的细节,谢谢!

[解决办法]
The __declspec keywords should be placed at the beginning of a simple declaration. THe compiler ignores, without warning, any __declspec keywords placed after * or & and in front of the variable identifier in a declaration.

A __declspec attribute specified in the beginning of a user-defined type declaration applies to the variable of that type. For example:

__declspec(dllimport) class X {} varX;
In this case, the attribute applies to varX. A __declspec attribute placed after the class or struct keyword applies to the user-defined type. For example:

class __declspec(dllimport) X {};
In this case, the attribute applies to X.

The general guideline for using the __declspec attribute for simple declarations is as follows:

decl-specifier-seq init-declarator-list;

The decl-specifier-seq should contain, among other things, a base type (e.g. int, float, a typedef, or a class name), a storage class (e.g. static, extern), or the __declspec extension. The init-declarator-list should contain, among other things, the pointer part of declarations. For example:

__declspec(selectany) int * pi1 = 0; //OK, selectany & int both part of decl-specifier
int __declspec(selectany) * pi2 = 0; //OK, selectany & int both part of decl-specifier
int * __declspec(selectany) pi3 = 0; //ERROR, selectany is not part of a declarator

Example

The following code declares an integer thread local variable and initializes it with a value:

// Example of the __declspec keyword
__declspec( thread ) int tls_i = 1;

热点排行