DEV Community

ib-dev-cpp
ib-dev-cpp

Posted on

4 4

Platform detection in C&C++

sometime when writing c or c++ code you need to write a code specific to the compiler/OS. and to this job the compiler have some predefined macros to detect the compiler or the OS.

Checking for OS:

to check which platform the code is compiled use these predefined macros:

for Windows              :  _WIN32
for Windows 64 bit       :  _WIN64 ( _WIN32 included )
for Mac OS & IOS         :  __APPLE__
for Linux & Linux-derived:  __linux__
for Android              :  __ANDROID__ ( __linux__ included )
for Akaros               :  __ros__
for NaCL                 :  __native_client__
for AsmJS                :  __asmjs__
for Fuschia              :  __Fuchsia__
Enter fullscreen mode Exit fullscreen mode

Checking for Compiler:

to check wich compiler used:

Visual Studio       _MSC_VER
gcc                 __GNUC__
clang               __clang__
emscripten          __EMSCRIPTEN__ (for asm.js and webassembly)
MinGW 32            __MINGW32__
MinGW-w64 32bit     __MINGW32__
MinGW-w64 64bit     __MINGW64__
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (1)

Collapse
 
pgradot profile image
Pierre Gradot •

There is an awesome page with a lot a defines from OS, compilers, etc: sourceforge.net/p/predef/wiki/Home/

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more