allocWithZone uses NULL, not nil for BNRImageStore


#1

I am working through the book, and I noticed that allocWithZone uses NULL in sharedStore for BNRImageStore (page 249), but nil for the sharedStore in BNRItemStore.

Is there some deep significance to this, or were the two chapters just to demonstrate that either is fine. It’s the first time I’ve seen NULL in Objective C, and whilst I know that they are defined to be the same thing at the moment, I was still a little confused at the sudden change.

Thanks,

Jonathan


#2

Conventionally, nil is used to represent 0 for pointers to objects where NULL is used to represent 0 for pointers to anything else. NSZone is declared to be a structure, so we use NULL. The thing is, it wouldn’t hurt to use nil, NULL, or 0, really, they are all the same thing. Under the hood, every class is just a structure anyway. Although, consistent, convention-conforming code looks good and is easier to read for everyone.


#3

Thanks for replying, Joe. I appreciate your response. I was just surprised to see NULL there. :slight_smile: