weird compiler warnings/errors in Xcode 2.0

I just upgraded to Tiger last night (from Panther), and now many of my Cocoa projects produce compiler warnings which never appeared before. In both of the following examples, selectedDevice is an io_object_t.

"warning: comparison between pointer and integer"
is produced by the following code:

Code:

if (selectedDevice != NULL) { //do stuff }

"warning: assignment makes integer from pointer without a cast"
is produced by the following code:

You said selectedDevice is an io_object_t - not an io_object_t pointer. As far as I can tell, pointers really haven't changed at all in GCC 4, I think it's that you are treating the io_object_t as a pointer when it's really just some sort of reference number. Perhaps replace all the NULLs with 0's or read the documentation on the io_object_t and see if there's a default or NULL value for it.

You can always run gcc_select as root (or with sudo) and change back to 3.3 to see if it's just 4.0 that brings out this problem. I would try compling with -Wall (all warnings) under both 3.3 and 4.0 to see if one errors when the other one just warns.

Andrew Wrote:I always figured "NULL" was a macro that simple pasted "0" into my code. Now I know better

Often, in pratice, it is; I wouldn't consider it the same thing though. NULL could be any internal way for marking that the pointer as pointing to nothing. Just as giving a pointer the value zero it not really a good idea, though often it works.

You can command-double-click on any symbol in Xcode and the file where it's defined comes up in another window. In the case of NULL you wind up with two possible paths, both of which wind up with NULL being defined as ((void *)0). Interestingly, the definition in stddef undefines whatever is defined for NULL in stdio. It still becomes ((void *)0) however.

[Edit] BTW, you can then get the full path to that file by right-click->Get Info in the text view.

iefan Wrote:If you look more closely you'll see that the ((void *) 0) only applies sometimes. Otherwise you have a __null or few other things such as 0 or 0L. It's a rather confusing set of ifdefs really.

I never found what __null was, it's not in any file on my system. So it's an internal GCC thing I assume.