We can use #ifdef __linux_
or #ifdef __APPLE__
to identify the user's operating system. But can we define different versions of the operating system? For example between macos Big Sur and macos Monterey.
In search of an answer, I came across the Availability.h library, but I didn't quite understand how to find the right version of OS
CodePudding user response:
You can test for the OS at runtime in C/C code like so:
if (__builtin_available( macOS 12.0, * ))
{
// Monterey or later
}
else
{
// before Monterey
}
Of course you'll have to think about what should happen when macOS 13 comes out.