Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4609582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:00:30+00:00 2026-05-22T01:00:30+00:00

If there’s some cross-platform C/C++ code that should be compiled on Mac OS X,

  • 0

If there’s some cross-platform C/C++ code that should be compiled on Mac OS X, iOS, Linux, Windows, how can I detect them reliably during preprocessor process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:00:31+00:00Added an answer on May 22, 2026 at 1:00 am

    There are predefined macros that are used by most compilers, you can find the list here. GCC compiler predefined macros can be found here.
    Here is an example for gcc:

    #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
       //define something for Windows (32-bit and 64-bit, this part is common)
       #ifdef _WIN64
          //define something for Windows (64-bit only)
       #else
          //define something for Windows (32-bit only)
       #endif
    #elif __APPLE__
        #include <TargetConditionals.h>
        #if TARGET_IPHONE_SIMULATOR
             // iOS, tvOS, or watchOS Simulator
        #elif TARGET_OS_MACCATALYST
             // Mac's Catalyst (ports iOS API into Mac, like UIKit).
        #elif TARGET_OS_IPHONE
            // iOS, tvOS, or watchOS device
        #elif TARGET_OS_MAC
            // Other kinds of Apple platforms
        #else
        #   error "Unknown Apple platform"
        #endif
    #elif __ANDROID__
        // Below __linux__ check should be enough to handle Android,
        // but something may be unique to Android.
    #elif __linux__
        // linux
    #elif __unix__ // all unices not caught above
        // Unix
    #elif defined(_POSIX_VERSION)
        // POSIX
    #else
    #   error "Unknown compiler"
    #endif
    

    The defined macros depend on the compiler that you are going to use.

    The _WIN64 #ifdef can be nested into the _WIN32 #ifdef because _WIN32 is even defined when targeting the Windows x64 version. This prevents code duplication if some header includes are common to both
    (also WIN32 without underscore allows IDE to highlight the right partition of code).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of porting some code from Linux to Mac OS X.
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is a field in my company's Contacts table. In that table, there is
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
there's a CMS system and there's aspx page without backend file. I can add
There is a vim function Send_to_Screen(text) which sends some text to a console screen
There is a strange bug which I can't solve. The bug is reproducable by
There is no problem to get the src or alt separately,but how can get
There is one method in Lookup<,> that is not in ILookup<,> : public IEnumerable<TResult>
There is a statement in the foudations of Qt Development book that goes as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.