Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Determine OS version at compile time?

Determine OS version at compile time?
Thread Tools
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
May 18, 2005, 02:30 AM
 
Hi everyone,
I was wondering if anybody knows how to detect the OS version at compile time? I want to know this specifically because between panther and tiger apple changed how appendBezierPath works. In 10.3, if you did [myPath appendBezierPath: otherPath] it would *return* the new one. Now, under Tiger, it returns void and instead does more what you'd think which is append otherPath to myPath.
Unfortunately, I need to be able to compile my program under 10.3 and 10.4, so I'm looking for a way to do something like this:
#ifdef _TIGER
[myPath appendBezierPath: otherPath];
#elif
[self setPath: [myPath appendBezierPath: otherPath]];
#endif

I'm pretty sure I can do this by just adding a -D_TIGER to my gcc flags, but I was wondering if GCC defines anything for you (for instance GCC defines __APPLE__).

Thanks!
gabe
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
May 18, 2005, 08:31 AM
 
Hmm, my Panther documentation says:

- (void)appendBezierPath:(NSBezierPath *)aPath

So, if the documentation is correct, it's never returned the new path...
[Wevah setPostCount:[Wevah postCount] + 1];
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
May 18, 2005, 08:52 AM
 
You can either check for AppKit's version or check for the method's presence:

http://cocoadevcentral.com/articles/000067.php

http://www.cocoabuilder.com/search/a...appkit+version
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
May 18, 2005, 08:53 AM
 
uname
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 18, 2005, 11:14 AM
 
It never returned it, you were relying on a magic coincidence. The fact that the compiler didn't warn you was a bug.
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
May 18, 2005, 12:07 PM
 
Hey Guys,
Thanks. Haha, that's pretty funny. Yeah it was really bad about what it'd warn me about. Nothing when I'd never return anything in a function that returned. I had warnings on too. Anyway, thanks a bunch.

Gabe
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
May 20, 2005, 09:14 PM
 
I'd actually still like an answer to the original question, for a similar reason. There's some NSTableView stuff that's deprecated on Tiger, but the replacement doesn't exist for earlier versions.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 20, 2005, 10:02 PM
 
What's wrong with checking AppKit's version, smeger? That actually sounds like a better solution than compile-time checking, because then you can dynamically use the right code for whichever version the user has.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
May 21, 2005, 12:11 AM
 
Because I get compile-time warnings for using an undefined method. And I always write my code to be warning-free.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
May 21, 2005, 02:38 AM
 
respondsToSelector: ?
[Wevah setPostCount:[Wevah postCount] + 1];
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
May 21, 2005, 03:24 AM
 
That's what I wound up doing, Wevah. But I don't like it, and I'd rather do a compile-time check.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
May 21, 2005, 04:14 AM
 
There are a bunch of defines you can check for if you want to go that route. I think using respondsToSelector: is the best way though, at least for shipping software.
[Wevah setPostCount:[Wevah postCount] + 1];
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
May 21, 2005, 07:10 AM
 
Originally Posted by smeger
That's what I wound up doing, Wevah. But I don't like it, and I'd rather do a compile-time check.
So you don't want to use it even if it's available when you're running on Tiger?

Look at AvailabilityMacros.h and the following things:
http://developer.apple.com/releaseno...ityMacros.html
http://developer.apple.com/technotes/tn2002/tn2064.html
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
May 21, 2005, 05:00 PM
 
Okay, this whole discussion was the result of a giant brain fart on my part. Sorry for wasting everyone's time.

I was thinking about things in terms of my own test code, rather than in terms of shipping code. As I was working on Tiger compatibility for one of my apps, I often compiled it on Tiger and I often compiled it on Panther. I like to compile with zero warnings, so my "without really thinking it through" idea was to add a compile-time check and compile in only the appropriate case.

Of course, this is a totally stupid idea if I'm actually shipping an app that can run on either Tiger or Panther. So, again, my apologies for the time waste.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2