__declspec
Microsoft 전용
스토리지 클래스 정보를 지정하기 위한 확장 특성 구문은 지정된 형식의 인스턴스가 아래에 나열된 Microsoft 특정 스토리지 클래스 특성과 함께 저장되도록 지정하는 키워드(keyword) 사용합니다 __declspec
. 다른 스토리지 클래스 한정자의 예로는 static
및 extern
키워드가 있습니다. 그러나 이러한 키워드(keyword) C 및 C++ 언어의 ANSI 사양의 일부이므로 확장 특성 구문에서 다루지 않습니다. 확장명 특성 구문은 C 및 C++ 언어에 대한 Microsoft 전용 확장을 간소화하고 표준화합니다.
문법
decl-specifier
:
__declspec (
extended-decl-modifier-seq
)
extended-decl-modifier-seq
:
extended-decl-modifier
opt
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
safebuffers
noalias
naked
jitintrinsic
empty_bases
noinline
dllimport
dllexport
noreturn
process
no_sanitize_address
restrict
novtable
selectany
spectre
allocate
appdomain
thread
allocator
code_seg
deprecated
nothrow
지원합니다. 또한 다음과 같은 COM 개체 특성 property
및 uuid
.를 지원합니다.
code_seg
, dllexport
,dllimport
, empty_bases
,naked
, noalias
, nothrow
, , no_sanitize_address
, property
, restrict
, , thread
selectany
및 uuid
스토리지 클래스 특성은 적용되는 개체 또는 함수 선언의 속성입니다. 이 특성은 thread
데이터 및 개체에만 영향을 줍니다. 및 spectre
특성은 naked
함수에만 영향을 줍니다. 및 dllexport
특성은 dllimport
함수, 데이터 및 개체에 영향을 줍니다. , selectany
및 uuid
특성은 property
COM 개체에 영향을 미칩니다.
이전 버전 _declspec
과의 호환성을 위해 __declspec
컴파일러 옵션 /Za
(언어 확장 사용 안 함) 을 지정하지 않는 한 동의어입니다.
__declspec
키워드(keyword) 단순 선언의 시작 부분에 배치해야 합니다. 컴파일러는 * 또는 > 다음에 배치된 모든 키워드(keyword) 경고 __declspec
없이 선언의 변수 식별자 앞에 무시합니다.
__declspec
사용자 정의 형식 선언의 시작 부분에 지정된 특성이 해당 형식의 변수에 적용됩니다. 예시:
__declspec(dllimport) class X {} varX;
이 경우 특성이 varX
에 적용됩니다. __declspec
또는 struct
키워드(keyword) 다음에 class
배치된 특성이 사용자 정의 형식에 적용됩니다. 예시:
class __declspec(dllimport) X {};
이 경우 특성이 X
에 적용됩니다.
단순 선언에 __declspec
특성을 사용하는 일반적인 지침은 다음과 같습니다.
decl-specifier-seq
init-declarator-list
;
decl-specifier-seq
무엇보다도 기본 형식(예int
: , , float
a 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 전용 종료
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기