다음을 통해 공유


__declspec (Windows CE 5.0)

Send Feedback

The __declspec keyword specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute.

The extended attribute syntax for specifying storage-class information uses the __declspec keyword, which specifies that an instance of a given type is to be stored with a Microsoft-specific storage-class attribute listed below.

Examples of other storage-class modifiers include the static and extern keywords. However, these keywords are part of the ANSI specification of the C and C++ languages, and as such are not covered by extended attribute syntax.

The extended attribute syntax simplifies and standardizes Microsoft-specific extensions to the C and C++ languages.

This is the extended attribute syntax for C++:

decl-specifier : __declspec ( extended-decl-modifier-seq ) 
extended-decl-modifier-seq : extended-decl-modifieroptextended-decl-modifier extended-decl-modifier-seq extended-decl-modifier :   align(#)  allocate(segname)  dllimport  dllexport  naked  noinline  noreturn  nothrow  novtable  property({get=get_func_name|, put=put_func_name})
  selectany  uuid(ComObjectGUID)

White space separates the declaration modifier sequence. Examples of the syntax appear in later sections.

Extended attribute syntax supports these Microsoft-specific storage-class attributes: align, allocate, dllexport, dllimport, naked, noinline, noreturn, nothrow, novtable, and selectany.

It also supports these COM-object attributes: property and uuid.

The naked, dllimport, dllexport, nothrow, property, selectany, and uuid storage-class attributes are properties only of the declaration of the object or function they are applied to.

Unlike the __near and __far keywords, which affect the type of object or function (in this case, 2- and 4-byte addresses), these storage-class attributes do not redefine the type attributes of the object itself.

The naked attribute affects functions only.

The dllimport and dllexport attributes affect functions, data, and objects.

The property, selectany, and uuid attributes affect COM objects.

The __declspec keywords should be placed at the beginning of a simple declaration. The compiler ignores, without warning, __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 guideline for using the __declspec attribute for simple declarations is as follows:

decl-specifier-seq init-declarator-list;

The decl-specifier-seq should contain a base type such as an int, a float, a typedef, or a class name; a storage class such as static or extern; or the __declspec extension.

The init-declarator-list should contain 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

See Also

Microsoft-Specific Modifiers

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.