Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Check for Undefined Function Calls

As described in “Loading,” in some situations your object code may successfully load, using weak linking, but certain function calls may be undefined because they are not available in the current system. To run successfully, your code must avoid calling those functions in system versions that do not support them. It can do this either by checking the system version at run time and globally taking a different code path based on the version, or by checking each function pointer for a null value before calling it.

For example, suppose you build your application to use features in Mac OS X version 10.3 (Panther) and to deploy back to Mac OS X version 10.2. (Jaguar). To use the HIAboutBox function, first available in Panther, you could use code like the following:

Listing 2-1  A function that checks for a null function pointer

void MyAboutBox(void)
    if(HIAboutBox != NULL)
        // Lots of code to display an about box with earlier technology.

Important: When checking for the existence of a symbol, you must explicitly compare it to NULL or nil in your code. You cannot use the negation operator ( ! ) to negate the address of the symbol.

When your code runs in Panther, it calls HIAboutBox to display the minimal default standard About box. When it runs in Jaguar, it displays an About box based on the code you wrote for Jaguar.

If you build this code with different settings, you should see the following results:

< Previous PageNext Page > Hide TOC

Last updated: 2006-11-07

Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice