__declspec

Microsoft 전용

스토리지 클래스 정보를 지정하기 위한 확장 특성 구문은 지정된 형식의 인스턴스를 아래에 나열된 Microsoft 특정 스토리지 클래스 특성과 함께 저장하도록 지정하는 키워드를 사용합니다 __declspec . 다른 스토리지 클래스 한정자의 예로는 staticextern 키워드가 포함됩니다. 그러나 이러한 키워드는 C 및 C++ 언어의 ANSI 사양의 일부이므로 확장 특성 구문에서 다루지 않습니다. 확장 특성 구문은 Microsoft 관련 확장을 C 및 C++ 언어로 단순화하고 표준화합니다.

문법

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

extended-decl-modifier-seq:
extended-decl-modifier 선택
extended-decl-modifier extended-decl-modifier-seq

extended-decl-modifier:
align( )
allocate(" segname")
allocator
appdomain
code_seg(" segname")
deprecated
dllimport
dllexport
empty_bases
hybrid_patchable
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 데이터 및 개체에만 영향을 줍니다. 및 naked 특성은 spectre 함수에만 영향을 줍니다. dllimportdllexport 특성은 함수, 데이터 및 객체에 영향을 줍니다. property, selectany, 및 uuid 특성은 COM 개체에 영향을 미칩니다.

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

키워드는 __declspec 단순 선언의 시작 부분에 배치해야 합니다. 컴파일러는 * 또는 > 다음에 배치된 키워드와 선언의 변수 식별자 앞에 있는 키워드를 경고 __declspec 없이 무시합니다.

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

__declspec(dllimport) class X {} varX;

이 경우 특성이 varX에 적용됩니다. __declspec 또는 class 키워드 다음에 배치된 특성이 struct 사용자 정의 형식에 적용됩니다. 다음은 그 예입니다.

class __declspec(dllimport) X {};

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

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

decl-specifier-seq init-declarator-list ;

decl-specifier-seq 무엇보다도 기본 형식(예int: , , floata 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 확장 스토리지 클래스 특성