C전처리기에서 OS(OS X/리눅스/윈도우 등)을 감지하려면?
조회수 9546회
1 답변
-
대부분의 컴파일러에서 쓸 수 있는 매크로 리스트는 [여기], GCC 컴파일러에서 미리 정의된 매크로는 [여기]를 봐주세요
gcc에 예제중
#ifdef _WIN32 //define something for Windows (32-bit and 64-bit, this part is common) #ifdef _WIN64 //define something for Windows (64-bit only) #endif #elif __APPLE__ #include "TargetConditionals.h" #if TARGET_IPHONE_SIMULATOR // iOS Simulator #elif TARGET_OS_IPHONE // iOS device #elif TARGET_OS_MAC // Other kinds of Mac OS #else # error "Unknown Apple platform" #endif #elif __linux__ // linux #elif __unix__ // all unices not caught above // Unix #elif defined(_POSIX_VERSION) // POSIX #else # error "Unknown compiler" #endif
이 매크로는 컴파일러에 따라 결과가 달라집니다
_WIN32
는 32비트(x86)뿐 만 아니라 windows를 감지하기 때문에The _WIN64 #ifdef
대신_WIN32 #ifdef
를 쓸 수도 있습니다
댓글 입력