다음을 통해 공유


__declspec

Microsoft 전용

스토리지 클래스 정보를 지정하기 위한 확장 특성 구문은 주어진 형식의 인스턴스가 아래에 나열된 Microsoft 전용 스토리지 클래스 특성으로 저장되도록 지정하는 __declspec 키워드를 사용합니다. 다른 스토리지 클래스 한정자의 예로는 staticextern 키워드가 있습니다. 그러나 이러한 키워드는 C 및 C++ 언어의 ANSI 사양에 포함되므로 확장 특성 구문에서 다루지 않습니다. 확장명 특성 구문은 C 및 C++ 언어에 대한 Microsoft 전용 확장을 간소화하고 표준화합니다.

문법

decl-specifier:
__declspec ( extended-decl-modifier-seq )

extended-decl-modifier-seq:
extended-decl-modifieropt
extended-decl-modifier extended-decl-modifier-seq

extended-decl-modifier:
align( number )
allocate(" segname ")
allocator
appdomain
code_seg(" segname ")
deprecated
dllimport
dllexport
empty_bases
jitintrinsic
naked
noalias
noinline
noreturn
nothrow
novtable
no_sanitize_address
process
property( { get=get-func-name | ,put=put-func-name } )
restrict
safebuffers
selectany
spectre(nomitigation)
thread
uuid(" ComObjectGUID ")

공백은 선언 한정자 시퀀스를 구분합니다. 뒤에 나오는 단원에 예제가 있습니다.

확장 특성 문법은 Microsoft 전용 스토리지 클래스 특성인 align, allocate, allocator, appdomain, code_seg, deprecated, dllexport, dllimport, empty_bases, jitintrinsic, naked, noalias, noinline, noreturn, nothrow, novtable, no_sanitize_address,process, restrict, safebuffers, selectany, spectre, 및 thread를 지원합니다. 또한 COM 개체 특성인 propertyuuid도 지원합니다.

code_seg, dllexport, dllimport, empty_bases, naked, noalias, nothrow, no_sanitize_address, property, restrict, selectany, thread, 및 uuid 스토리지 클래스 특성은 적용되는 개체나 함수의 선언에만 해당되는 속성입니다. thread 특성은 데이터 및 개체에만 영향을 줍니다. nakedspectre 특성은 함수에만 영향을 줍니다. dllimportdllexport 특성은 함수, 데이터, 및 개체에 영향을 줍니다. property, selectany,및 uuid특성은 COM 개체에 영향을 줍니다.

이전 버전과의 호환성을 위해 _declspec__declspec의 동의어입니다. 단, 컴파일러 옵션 /Za(언어 확장 사용 안 함)가 지정된 경우는 예외입니다.

__declspec 키워드는 간단한 선언의 시작 부분에 배치해야 합니다. 컴파일러는 선언에서 * 또는 & 뒤와 변수 식별자 앞에 오는 __declspec 키워드를 경고 없이 무시합니다.

사용자 정의 형식 선언의 시작 부분에 지정된 __declspec 특성은 해당 형식의 변수에 적용됩니다. 예시:

__declspec(dllimport) class X {} varX;

이 경우 특성이 varX에 적용됩니다. class 또는 struct 키워드 뒤에 오는 __declspec 특성은 사용자 정의 형식에 적용됩니다. 예시:

class __declspec(dllimport) X {};

이 경우 특성이 X에 적용됩니다.

간단한 선언에 __declspec 특성을 사용하는 데 대한 일반적인 지침은 다음과 같습니다.

decl-specifier-seq init-declarator-list ;

decl-specifier-seq에는 무엇보다도 기본 형식(예: int, float, typedef, 또는 클래스 이름), 스토리지 클래스(예: static, extern) 또는 __declspec 확장명이 포함되어야 합니다. init-declarator-list에는 무엇보다도 선언의 포인터 부분이 포함되어야 합니다. 예시:

__declspec(selectany) int * pi1 = 0;   //Recommended, 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 of the __declspec keyword
__declspec( thread ) int tls_i = 1;

Microsoft 전용 종료

참고 항목

키워드
C 확장 스토리지 클래스 특성