Thread: Platform specific

  1. #1

    Question Platform specific

    I'd like my programs to work for both a windows operating system and a mac. I know that it can not be done in a function but I want to do somehing like

    If (mac)
    #include 'mac.h'
    #inlcude 'win.h'

    I'm sure it can't be that simple, but that's the effect I'd like it to have. That way if I wanted a clear screen function, I'd make one with clrscr (); and one with system ("CLS"); put each in the correct header file then later on just type clearscreen (); and it would call the appropriate function depending on which header was included. I hope that made sence. I pretty much want to make two identical header files but they each have platform specific commands. During compile time, my source file should determine what platform it's being compiled on and #include the appropriate header file. I don't know anyway of doing this. Help is appreciated.
    Steve O.

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    actually it is that simple

    you use these and check for definitions that comilers put in.
    the MSVC uses WIN32 to define a windows program. I'm not sure for other OSs though. Look for the preprocessor definitions for your compiler.

    #if defined()

    like this

    #ifdef WIN32
    // include windows header
    // headers of other OSs

  3. #3

  4. #4


    Thanks, some things are just too obvious to realize. Like when I spent an hour making a function that does the exact same thing as one already defined in iostream. Sounds simple enough, if I have any problems with it I'll be back.
    Steve O.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. platform specific API or C standard API
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 01:32 AM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Platform Specific...
    By Cheeze-It in forum A Brief History of
    Replies: 5
    Last Post: 09-29-2002, 01:48 AM