[C/C++] OS 구분 전처리기 매크로

출처 : http://fogeaters.cafe24.com/xe/board11/13578


* 리눅스


#if defined(__linux__)
/* Linux. --------------------------------------------------- */

#endif


* OSX, iOS


#if defined(__APPLE__) && defined(__MACH__)
/* Apple OSX and iOS (Darwin). ------------------------------ */
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1
/* iOS in Xcode simulator */

#elif TARGET_OS_IPHONE == 1
/* iOS on iPhone, iPad, etc. */

#elif TARGET_OS_MAC == 1
/* OSX */

#endif
#endif


* 윈도우즈


#if defined(_WIN64)
/* Microsoft Windows (64-bit). ------------------------------ */

#elif defined(_WIN32)
/* Microsoft Windows (32-bit). ------------------------------ */
  
#endif


[참고자료] http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system

http://beefchunk.com/documentation/lang/c/pre-defined-c/preos.html

위로 스크롤