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:
"warning: assignment makes integer from pointer without a cast"
is produced by the following code:
What do you think the problem is? Is it my code, Xcode 2.0, or GCC4?
Thanks in advance,
Andrew G.
"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.
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"
"warning: comparison between pointer and integer"
"warning: passing argument 4 of 'IORegistryEntryCreateCFProperty' makes integer from pointer without a cast"
Code:
CFNumberRef locationID;
locationID = IORegistryEntryCreateCFProperty( interfaceToCheckLocationOf,
CFSTR(kIOHIDLocationIDKey),
kCFAllocatorDefault,
NULL);"warning: comparison between pointer and integer"
Code:
if (IOIteratorNext(deviceInterfaceIterator) == NULL) { //do stuff }
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.
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.
~ Travis
Code:
CFNumberRef locationID;
locationID = IORegistryEntryCreateCFProperty( interfaceToCheckLocationOf,
CFSTR(kIOHIDLocationIDKey),
kCFAllocatorDefault,
NULL);
~ Travis
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:
-[NSMutableAttributedString setAttributes:range:] doesn't return anything:
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;
typedef __darwin_natural_t natural_t;
typedef natural_t mach_port_name_t;
typedef mach_port_name_t mach_port_t;
typedef mach_port_t io_object_t;-[NSMutableAttributedString setAttributes:range:] doesn't return anything:
Code:
- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRangeCode:
typedef unsigned int __darwin_natural_t;
typedef __darwin_natural_t natural_t;
typedef natural_t mach_port_name_t;
typedef mach_port_name_t mach_port_t;
typedef mach_port_t io_object_t;Man, that obnious set of typedefs. I'm glad OSC looked it up and not me.
~ Travis
Thanks guys! Everything works now 
I always figured "NULL" was a macro that simple pasted "0" into my code. Now I know better

I always figured "NULL" was a macro that simple pasted "0" into my code. Now I know better
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:
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?
Code:
NSMutableParagraphStyle *centeredParagraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[centeredParagraphStyle setAlignment:NSCenterTextAlignment];
[string_attributes setObject:centeredParagraphStyle
forKey:NSParagraphStyleAttributeName];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?
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.
~ Travis
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.
Still no reason to confuse the two.
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)
in /usr/include/stdio.h:
#define NULL __DARWIN_NULL
and in /usr/include/sys/_types.h:
#define __DARWIN_NULL ((void *)0)
Andrew Wrote: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)
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.
~ Travis
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.
[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.
Here's the full set of def's for __DARWIN_NULL (nicely indented):
Code:
#ifdef __cplusplus
#ifdef __GNUG__
#define __DARWIN_NULL __null
#else /* ! __GNUG__ */
#ifdef __LP64__
#define __DARWIN_NULL (0L)
#else /* !__LP64__ */
#define __DARWIN_NULL 0
#endif /* __LP64__ */
#endif /* __GNUG__ */
#else /* ! __cplusplus */
#define __DARWIN_NULL ((void *)0)
#endif /* __cplusplus */So, as long as you're not using C++, NULL should always be ((void *)0) on Mac OS X (well... on Tiger anyway).
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.
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.
Code:
@interface NSParagraphStyle(DBGBP)
- (unsigned) count;
@end
@implementation NSParagraphStyle(DBGBP)
- (unsigned) count
{
[NSException raise:@"Invalid Selector"
format:@"NSParagraphStyle does not respond to count"];
}
@endSet 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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Weird Compiler WARNING... help? | Elphaba | 1 | 1,767 |
Aug 10, 2009 10:51 PM Last Post: Elphaba |
|
| Curious Compiler Issue? | WhatMeWorry | 1 | 2,193 |
Jan 16, 2007 03:52 PM Last Post: OneSadCookie |
|
| Weird errors with std::map | ermitgilsukaru | 8 | 3,738 |
Nov 30, 2006 04:10 AM Last Post: DoG |
|
| Intel Mac -> Many Warnings (deprecated functions) | dave05 | 3 | 3,621 |
Sep 6, 2006 03:19 PM Last Post: aarku |
|
| compiler (pre-processing?) error of SDL project | WhatMeWorry | 2 | 2,600 |
Oct 14, 2005 09:09 PM Last Post: WhatMeWorry |
|

