![]() |
|
weird compiler warnings/errors in Xcode 2.0 - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: weird compiler warnings/errors in Xcode 2.0 (/thread-5541.html) Pages: 1 2 |
weird compiler warnings/errors in Xcode 2.0 - Andrew - May 8, 2005 01:17 PM 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: Code: selectedDevice = NULL;What do you think the problem is? Is it my code, Xcode 2.0, or GCC4? Thanks in advance, Andrew G. weird compiler warnings/errors in Xcode 2.0 - Andrew - May 8, 2005 01:34 PM Here are 2 more examples of how NULLs aren't being treated correctly (IMHO) by the compiler: "warning: passing argument 4 of 'IORegistryEntryCreateCFProperty' makes integer from pointer without a cast" Code: CFNumberRef locationID;"warning: comparison between pointer and integer" Code: if (IOIteratorNext(deviceInterfaceIterator) == NULL) { //do stuff }weird compiler warnings/errors in Xcode 2.0 - iefan - May 8, 2005 01:39 PM 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. weird compiler warnings/errors in Xcode 2.0 - iefan - May 8, 2005 01:42 PM Code: CFNumberRef locationID;
weird compiler warnings/errors in Xcode 2.0 - OneSadCookie - May 8, 2005 01:44 PM These are problems with your code. NULL is a pointer. Don't assign it to non-pointer variables. io_object_t ain't a pointer type: Code: typedef unsigned int __darwin_natural_t;-[NSMutableAttributedString setAttributes:range:] doesn't return anything: Code: - (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRangeweird compiler warnings/errors in Xcode 2.0 - iefan - May 8, 2005 01:46 PM Code: typedef unsigned int __darwin_natural_t;Man, that obnious set of typedefs. I'm glad OSC looked it up and not me.
weird compiler warnings/errors in Xcode 2.0 - Andrew - May 8, 2005 01:49 PM Thanks guys! Everything works now ![]() I always figured "NULL" was a macro that simple pasted "0" into my code. Now I know better
weird compiler warnings/errors in Xcode 2.0 - Andrew - May 8, 2005 02:04 PM That stuff about centering a paragraph (which I deleted from my original post because I realized my own stupid mistake after posting) is still causing trouble. I've changed the code to this: Code: NSMutableParagraphStyle *centeredParagraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];and it compiles fine... but now I get a runtime error: *** -[NSParagraphStyle count]: selector not recognized [self = 0x4770250] could this be a bug in AppKit? weird compiler warnings/errors in Xcode 2.0 - iefan - May 9, 2005 09:22 AM 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. weird compiler warnings/errors in Xcode 2.0 - Puzzler183 - May 9, 2005 09:27 AM Uhm, actually, I'm fairly certain that according to the standard, if you cast NULL to an int it must be zero. I don't have a copy to look it up in but yeah, NULL must basically be (void *) 0. Still no reason to confuse the two. weird compiler warnings/errors in Xcode 2.0 - Andrew - May 9, 2005 09:53 PM with regards to the NULL stuff, I found the definitions: in /usr/include/stdio.h: #define NULL __DARWIN_NULL and in /usr/include/sys/_types.h: #define __DARWIN_NULL ((void *)0) weird compiler warnings/errors in Xcode 2.0 - iefan - May 11, 2005 08:29 AM Andrew Wrote:with regards to the NULL stuff, I found the definitions: 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. weird compiler warnings/errors in Xcode 2.0 - AnotherJake - May 11, 2005 08:42 AM 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. weird compiler warnings/errors in Xcode 2.0 - Andrew - May 11, 2005 05:02 PM 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. Here's the full set of def's for __DARWIN_NULL (nicely indented): Code: #ifdef __cplusplusSo, as long as you're not using C++, NULL should always be ((void *)0) on Mac OS X (well... on Tiger anyway). weird compiler warnings/errors in Xcode 2.0 - VolganPoet - May 12, 2005 12:03 PM Andrew, you might try setting a break point on the call. Since count isn't a selector defined for NSParagraphStyle, you'll need to make one to break on. Code: @interface NSParagraphStyle(DBGBP)Set a break point in the new count method, run the debugger, then you'll see where the call came from and hopefully what the bug is. Oh, and delete the category when you're finished. |