Going through some documentation on modifying CGImageRef data, I came across a strange example -- It went something along the lines of this pseudocode:
void *data = Allocate space for data;
if (data != NULL) Manipulate data;
if (data) Free data;
This got me wondering! What is the difference between the boolean operation if (data != NULL)
and the boolean operation if (data)
.
To be more specific, how do pointers behave in Objective C when they are treated as booleans? Attempting to google this, I only found myriads of questions relating to pointers-to-booleans, as opposed to pointers being evaluated as booleans.
They're exactly the same. Non-zero values of any type are interpreted as "true" in C, and by extension in Objective-C. C doesn't even have a boolean type.
NULL
in SQL, None
in Python and Nothing
in Haskell. Programming is a subtle discipline - outis 2012-04-04 06:43