As far as I remember, the keyword static, for C++, inside a function call meant that the static variable was initialized the first time the declaration was encountered.
I have used the static keyword in an Objective-C member function and the static variable seems to be initialized immediately (with a non-compile-time constant subscriber). Note, that I am coding in a mixed file type .mm of Objective-C.
- (id) init
{
[self initSubsciber];
[self relayMessages];
}
- (void) initSubscriber
{
subscriber= PTR;
}
- (void) relayMessages
{
// Example 2-2 (mspoller.c), 0MQ book pg.43
// Initialize poll set
static zmq_pollitem_t items[] = {
{ subscriber, 0, ZMQ_POLLIN, 0 },
};
In the above example, since I am calling initSubscriber before relayMessages, I would expect the subscribermember variable pointer to be equal to PTR, not NULL, because the zmq_pollitem_t line hasn't been called. Yet, it is NULL.
Has the behavior of static changed in the various versions of C++? And, how is the behavior defined in Objective-C in comparison?