runtime and type encoding confusion on 64-bit

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
I am trying to understand what's going wrong in a weird class for  
which I'm trying to use runtime functions to access ivars (as the  
class doesn't define accessors). The context is a 64-bit executable  
(which is relevant).

The class has an ivar called (for this argument) "count" of type  
"unsigned int" (ivar_getTypeEncoding() returns "I" and also class-dump  
shows it as "unsigned int", yes I'm talking about arch=x86_64), so I'm  
trying to get the value as follows:

unsigned int count;
object_getInstanceVariable(obj, "count", (void *)&count);

This crashes with an "EXC_BAD_ACCESS"  signal.

However when I do the following it works:

NSUInteger count;
object_getInstanceVariable(obj, "count", (void *)&count);

This makes no sense to me, as this is the wrong type.

Does anyone understand why this can work when I do it wrong and does  
not work when I do it right?

I do know that the type of the ivar probably should be NSUInteger=long  
long for 64 bits, but that's not my fault (it's not my class).

Thanks,
Christiaan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.