bgyer.blogg.se

Macos c programming
Macos c programming












In this example, we are detecting if we have a Windows OS or a Linux based OS. #if TARGET_OS_IPHONE & TARGET_IPHONE_SIMULATOR In this example, we use the macros of Apple OS to detect which Apple OS like MacOS or iPhone is being used. #ifdef _WIN32 // Includes both 32 bit and 64 bit

macos c programming

For Windows, our table will be: Operating SystemĪs _WIN32 is present in both 32 bit and 64 bit Windows Operating System, we need to first check the presence of _WIN32 to confirm that it is a Windows Operating System and then, check the presence of _WIN64 to confirm whether it is a 64 bit Windows Operating System or a 32 bit Windows Operating System.įollowing is the code to check your Windows OS: #include In the following example, we are focused on detecting the flavor of Windows we are running which can be a 64 bit or 32 bit.

macos c programming

We will go through some basic examples and explore the use of this features in real life as well. Note that the macros are valid for GNU GCC and G++ and may vary for other compilers. Printf("You have Windows Operating System") įollowing is the list of macros defined based on the Operating System: Operating System Similarly, other operating systems have specific macro defined by the compiler.Įxample of checking Windows OS: #ifdef _WIN32 So, if the macro _WIN32 is defined, we are on Windows. For example, on Windows platform, the compiler has a special macro named _WIN32 defined. To check the operating system of the host in a C or C++ code, we need to check the macros defined by the compiler (GNU GCC or G++). Reading time: 30 minutes | Coding time: 5 minutes














Macos c programming