gcc: What you can and what you cannot do in +load
1
1 8.2.1 What You Can and Cannot Do in '+load'
1 -------------------------------------------
1
1 '+load' is to be used only as a last resort. Because it is executed
1 very early, most of the Objective-C runtime machinery will not be ready
1 when '+load' is executed; hence '+load' works best for executing C code
1 that is independent on the Objective-C runtime.
1
1 The '+load' implementation in the GNU runtime guarantees you the
1 following things:
1
1 * you can write whatever C code you like;
1
1 * you can allocate and send messages to objects whose class is
1 implemented in the same file;
1
1 * the '+load' implementation of all super classes of a class are
1 executed before the '+load' of that class is executed;
1
1 * the '+load' implementation of a class is executed before the
1 '+load' implementation of any category.
1
1 In particular, the following things, even if they can work in a
1 particular case, are not guaranteed:
1
1 * allocation of or sending messages to arbitrary objects;
1
1 * allocation of or sending messages to objects whose classes have a
1 category implemented in the same file;
1
1 * sending messages to Objective-C constant strings ('@"this is a
1 constant string"');
1
1 You should make no assumptions about receiving '+load' in sibling
1 classes when you write '+load' of a class. The order in which sibling
1 classes receive '+load' is not guaranteed.
1
1 The order in which '+load' and '+initialize' are called could be
1 problematic if this matters. If you don't allocate objects inside
1 '+load', it is guaranteed that '+load' is called before '+initialize'.
1 If you create an object inside '+load' the '+initialize' method of
1 object's class is invoked even if '+load' was not invoked. Note if you
1 explicitly call '+load' on a class, '+initialize' will be called first.
1 To avoid possible problems try to implement only one of these methods.
1
1 The '+load' method is also invoked when a bundle is dynamically loaded
1 into your running program. This happens automatically without any
1 intervening operation from you. When you write bundles and you need to
1 write '+load' you can safely create and send messages to objects whose
1 classes already exist in the running program. The same restrictions as
1 above apply to classes defined in bundle.
1