다음을 통해 공유


typeof, __typeof__ (C23)

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

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

typeof 구문

typeof(type)
typeof(constant-expression)
__typeof__(constant-expression)

typeof 예제

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

// Compile with /std:clatest

#include <stdio.h>

double func()
{
    3.14;
}

#define POINTER(T) typeof(T*)

int main()
{
    auto a = func(); // the type for a (double) is inferred, but requires initialization at point of declaration
    typeof(func()) b; // the type for b is double, but didn't have to be initialized at point of declaration

    // Some declarations using typeof
    POINTER(int) p1 = NULL; // p1 is int*

    typeof(double(void))* pFunc = func; // pFunc is a pointer to a function that takes no arguments and returns a double
    printf("pFunc() returns %f\n", pFunc());

    return 0;
}

요구 사항

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

참고 항목

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