I used below code in the past to check between linux and windows
#include<stdio.h> int main(int argc, char *argv[]) { #ifdef _WIN32 printf("in Windows"); #endif #ifdef linux printf("In Linux"); #endif return 0; }
Usually the entire toolchain has its own predefined macros, so you need to use these macros to determine which one is this.
A list of such predefined macros.
http://sourceforge.net/p/predef/wiki/OperatingSystems/
Yes, as a side note. Here OS detection occurs using compile-time macros. So, according to the toolchain, the corresponding macro definition will go in the assembly.
To detect the OS version at runtime , as in java, we do
System.getProperty("os.name")
The same thing in C / C ++ we do not have an API.
On POSIX systems using uname 'we can get the OS name.
source share