Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: preprocessor directive to determine OS?



To use the macros that are used by Apple in their headers, check out
ConditionalMacros.h.

If you're only going to be dealing with different sets of code for different
operating systems, check out those that start with TARGET_OS_....

If you're wanting to make sure your code will only pull in certain APIs,
then you'll want to look at TARGET_API_MAC_... macros, most likely
TARGET_API_MAC_OSX will be of great interest to you; however, if you're
wanting to possibly target OS 8.6 and later using the Carbon set of APIs,
then it would be better to use TARGET_API_MAC_CARBON and then do API-NULL
tests and Gestalt calls to check on the presence of runtime functionality
(this is a big thing in and of itself, based on the presence of
documentation for each needed API).

To some extent, you may also be interested in TARGET_RT_..., but I doubt
you'll need to look at writing too much conditional code that wouldn't
already be taken care of with the TARGET_OS... and TARGET_API_MAC... macros
(by the way, here's one need for macros that the anti-macrocytes can't argue
against).

Since you've mentioned that you will be writing a cross-platform application
in C/C++, then I would recommend writing a set of abstract classes that are
completely cross-platform in their calling conventions, possibly taking a
(void*) as an extra platform-specific parameter where needed (I've used such
a method when needing to deal with WIN APIs that need a DC while Mac code
would implicitly use the current port, a "global" setting). Then, write
some platform-specific derived classes that will deal with the issues
related to each particular platform. Of course, put as much functionality
within the abstract classes as possible and try to only put
platform-specific code in the derived classes. Using this approach will
help you minimize the need for using macros throughout your code, since you
can then isolate the platform-specific code into separate files.

As a matter of working things through, you may find exceptions where you
absolutely must include platform-specific code in your abstract/base
classes. Where possible, try to move that code into the platform-specific
derived classes and rewrite your methods and parameters to get rid of such
needs.

You will find this to be a very iterative process, since it sounds like
you're starting from scratch and targeting more OSes than the "big two"
(according to our development perspectives, at least).
________________________________________________________________________
Gary L. Wade
Product Development Consultant
DesiSoft Systems | Voice: 214-642-6883
9619 E. Valley Ranch Parkway | E-Mail: email@hidden
Suite 2125 | Web: http://www.desisoftsystems.com/
Irving, TX 75063 |

Want a name worthy of a Star Wars character?
Download DSS Name Convoluter today from DesiSoft Systems at
http://www.desisoftsystems.com/
________________________________________________________________________

On 8/31/03 4:34 PM, "Ilya Maykov" <email@hidden> wrote:

> Hi all,
>
> I have a fairly simple question. I'm writing a C/C++ application and
> want to make it cross-platform, so it will include different modules
> for different operating systems. The first target system is OS X 10.2
> or higher, with an eventual port to Win32. Can someone tell me, what
> are the macros used by OS X to indicate the OS name and version? For
> example, to have system-specific code I would do something like this:
>
> #if defined MAC_OS_X
> // OS X specific code
> #elif defined WINDOWS
> //windows specific code
> #elif defined SOME_OTHER_OS
> //some other code
> ...
> ...
>
> Well you get the picture. Anyway, I need to know what macros to put in
> instead of my fake "MAC_OS_X" and "WINDOWS" macros. Thanks a lot.
>
> Ilya Maykov
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >preprocessor directive to determine OS? (From: Ilya Maykov <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.