• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best way to get warnings for 10.5 only calls?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to get warnings for 10.5 only calls?


  • Subject: Re: Best way to get warnings for 10.5 only calls?
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 30 Jan 2008 19:12:42 -0600

On Jan 30, 2008, at 4:41 PM, Knowledge Engineering wrote:

Thanks, that worked, although I was hoping for a checkbox!
So is the official way to comment in my 10.5 only code still:
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
 ...
 #endif
Right? Seems to work.

I don't that will achieve what you want. Ultimately, you will (probably) build one release version of your product. So, that build will either target the 10.5 SDK or the 10.4u one, and the code guarded in that way will either be compiled in or not. In other words, using preprocessor directives makes the decision at compile time.


This will just mask the issue, because all of your warnings will go away when you switch to the 10.4u SDK, but your program will fail on Tiger systems if you build your release against the 10.5 SDK.

You want to use run-time checks.

For C API, you want to test if the symbol has a non-NULL address:

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
if (SomeLeopardOnlyFunction != NULL)
	SomeLeopardOnlyFunction(args);
else
#endif
{
	// Fallback to Tiger-appropriate code
}

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
if (&SomeLeopardOnlyVariable != NULL)
	/* Use the variable */;
else
#endif
	// Tiger-appropriate code


For Objective-C API, you can check for the relevant selector, or otherwise use the introspection facilities:


#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
if ([object respondsToSelector:@selector(someLeopardOnlyMethod)])
	[object someLeopardOnlyMethod];
else
#endif
	// Tiger-appropriate code


Note, that the preprocessor conditionals are only there to quiet the warnings/errors you get from test-compiling against the 10.4u SDK *after* you've implemented the proper run-time checks and fallbacks. Keep in mind that the code within those conditionals _will_ be run in any binary built against the 10.5 SDK, even when running on Tiger, so it must be safe on that platform.


Note also that I test against MAC_OS_X_VERSION_10_4 rather than MAC_OS_X_VERSION_10_5, because the latter isn't defined in the 10.4u SDK and will be treated as though it's 0.

-Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Best way to get warnings for 10.5 only calls? (From: Knowledge Engineering <email@hidden>)
 >Re: Best way to get warnings for 10.5 only calls? (From: Knowledge Engineering <email@hidden>)

  • Prev by Date: Loadable Bundle Question
  • Next by Date: recursive header search path bug
  • Previous by thread: Re: Best way to get warnings for 10.5 only calls?
  • Next by thread: Re: Best way to get warnings for 10.5 only calls?
  • Index(es):
    • Date
    • Thread