(sending this to the list since I've seen this too many times already..)
Joshua,

> ...
>The flow of my logic is sound (or sound enough).  The problem is, I seem to
>be violating some ObjC rule with respect to assigning data types.
>Henceforth, here is what happened when I compiled...
>
>ThisFile.m: In function `-[ThisFile.m appendToResponse:inContext:]':
>ThisFile.m:116: incompatible types in assignment
>ThisFile.m:117: warning: comparison of distinct pointer types lacks a cast
>ThisFile.m:77: warning: `aRange' might be used uninitialized in this
>function
>
>Now, in the online documentation, it says that the NSString method
>"rangeOfCharacterFromSet" takes as it's argument an NSCharacterSet object
>(in this case "NSCharcterSet * anInvertedCharSet"0 and returns an NSRange
>object  (in this case "NSRange * aRange"), so according to the docs, I
>shouldn't be getting this error.  That is obviously not the case. There must
>be some detail I am overlooking. Any suggestions would be very helpful.

Well, the problem is that you are reading what you want the docs to say,
not what the docs really say. :-)

NSRange is not an object like NSArray and friends (i.e. an ObjC class),
but rather a small C structure passed around on the stack (just like an int).
If you declare a variable to be of type NSRange* you declare a pointer to
this small structure, and that's something very different that the
structure itself. Allocating small things like NSRange, NSPoint or NSSize
via regular memory allocation would only slow down things unnecesarily.
If you check out NSGeometry.h you'll find a lot of small, inlined functions
that help you deal with them. Another tip: don't write "SomeClass *anObject"
but rather "SomeClass* anObject". This makes the real type of the variable
(pointer-to-something) more explicit and helps to spot errors like yours
much, much earlier. In other words: don't expect an NSRange*, but only
an NSRange.

hope this clears up the confusion about the warnings!

Holger

Reply via email to