Checking Platforms

This is a discussion on Checking Platforms within the C++ Programming forums, part of the General Programming Boards category; I am working on a projest that runs on both Windows and Mac platforms. This is my first time trying ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    1

    Checking Platforms

    I am working on a projest that runs on both Windows and Mac platforms. This is my first time trying to code anything that supports multiple platforms. What I need to know is how do you check in code which platform the user is running? I need to write some stuff that will be Windows specific to check some registry entries and only want that code to run if the OS is a Windows platform. Is there an easy way to do this?

    edit: I am using MS VC++ 6.0
    Last edited by Elrek; 03-31-2004 at 10:02 AM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Is there an easy way to do this?
    You can use conditional compilation.
    Code:
    #ifdef _WIN32
    // Do Windows specific operations
    #endif
    Though conditionally compiling code directly in the source is ugly and hurts maintainability. A cleaner way would be to conditionally include the headers that you need and use wrapper functions that perform the necessary operations but can be used on both platforms. That way the code doesn't need to be changed, only the platform specific headers.
    My best code is written with the delete key.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Lightbulb You need two different executables.

    I assume that you know that you will need two different executables. One for Windows and one for the Mac.
    I am using MS VC++ 6.0
    I'm 99.5% sure that MSVC++ can't create a Mac executable. So, you'll need to use a different compiler for this. Normally, you would compile the Mac code on the Mac. There are cross-compilers that compile code on one platform to run on another platform. These are usuaslly used for embedded systems, or other special applications. I don't even know of any Windows compilers that cross-compile to a Mac exe. You'll have less trouble if you don't use a cross-compiler.

    Your source will include common C++ standard code, Windows specific code, and Mac specific code. If you use a multi-platform GUI library, you will have some common GUI code also.

    I've never done anything like this before, but I would try to keep the incompatable code in seperate modules/files.
    Last edited by DougDbug; 03-31-2004 at 06:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 07:57 PM
  4. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 10:05 AM
  5. Platforms
    By okinrus in forum Game Programming
    Replies: 0
    Last Post: 04-05-2004, 06:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21