Distinguish the specify code in different OS

To distinguish the OS: you can use the preprocessor: __linux__ and _WIN32 , thay sare known to the compiler.

The source code example is:

 

#ifdef __linux__ 
 
// Linux Includes Here
#endif 
 
#ifdef _WIN32 || _WIN64 
 
// Windows Includes Here 
#endif 

 

The function:

bool probe() { 
#ifdef TARGET_OS_MAC 
  return pro_macosx(); 
#elif defined __linux__ 
  return pro_linux(); 
#elif defined _WIN32 || defined _WIN64 
  return pro_win(); 
#else 
#error "unknown platform" 
#endif 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章