typeof_unqual, __typeof_unqual__ (C23)

C23 표준 typeof_unqual 에서 새로 추가된 연산자는 식카드constvolatilerestrict의 형식을 반환하는 단항 연산자입니다. 형식 선언, 형식 캐스트, 형식 검사 등에서 사용할 수 있습니다. 변수, 함수 또는 C 식의 형식을 가져옵니다.

__typeof_unqual__ 키워드(keyword) .와 동일한 기능을 typeof_unqual제공하는 Microsoft 전용 확장입니다. __typeof_unqual__ 이 키워드(keyword) C의 모든 버전(뿐만 /std:clatest아니라)에 대해 컴파일할 때 사용할 수 있다는 점에서만 다르 typeof_unqual 며 지원하는 __typeof_unqual__다른 컴파일러 간에 코드를 쉽게 포팅할 수 있습니다.

typeof_unqual 구문

typeof_unqual(type)
typeof_unqual(constant-expression)
__typeof__unqual(constant-expression)

typeof_unqual 예제

이 예제에서는 사용 typeof_unqual()하지만 사용하는 경우 __typeof_unqual__동작은 동일합니다.

// Compile with /std:clatest and /experimental:c11atomics
#include <stdatomic.h>

// A function that takes an atomic int pointer, but uses a non-atomic copy of the value
void func(_Atomic(int) * pAtomic)
{
    typeof_unqual(*pAtomic) local = *pAtomic;

    // Use local non-atomic copy of value
}

int main()
{
    int* const cpVar1 = 2;
    typeof_unqual(cpVar1) pVar2 = 3;
    pVar2 = 4; // no error because pi is not const. cpVar1 = 4 would be an error.

    _Atomic(int)i = 42;
    func(&i);

    return 0;
}

요구 사항

Visual Studio 17.9 이상 또는 cl.exe 버전 19.39.33428 이상이 필요합니다. 사용하려면 .를 /std:clatest사용하여 typeof_unqual컴파일합니다.

참고 항목

/std(언어 표준 버전 지정)