1 min read

UINT_PTR type

UINT_PTR type
Photo by Brian Kostiuk / Unsplash

64비트 호환 프로그래밍을 위해 _PTR 접미사 (type for pointer precision의 뜻)가 붙는 형들이 새로 정의되었다는 것을 알았다.
포인터 연산을 위해 포인터 변수를 정수형 변수로 type casting 할 때 발생하는 문제를 해결하기 위해 도입된 듯. 이 중 UINT_PTR 형인 UINT_PTR 형은 다음과 같이 정의되어 있다.

#if defined(_WIN64)
    typedef unsigned __int64 UINT_PTR;
#else
    typedef unsigned int UINT_PTR;
#endif

원래 이걸 찾게 된 이유는 SOCKET 형의 정체가 UINT_PTR 형이었기 때문이다.

// winsock2.h:
typedef UINT_PTR SOCKET;
— END OF POST.