Ivar definitions show 'long' type encoding as 'long long' type encoding

Posted by Frank C. on Stack Overflow See other posts from Stack Overflow or by Frank C.
Published on 2010-03-18T02:36:33Z Indexed on 2010/03/18 2:41 UTC
Read the original article Hit count: 773

Filed under:
|

I've found what I think may be a bug with Ivar and Objective-C runtime. I'm using XCode 3.2.1 and associated libraries, developing a 64 bit app on X86_64 (MacBook Pro).

Where I would expect the type encoding for the following "longVal" to be 'l', the Ivar encoding is showing a 'q' (which is a 'long long').

Anyone else seeing this? Simplified code and output follows:

Code:

#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Bug : NSObject
{
    long        longVal;
    long long   longerVal;
}
@property (nonatomic,assign) long longVal;
@property (nonatomic,assign) long long longerVal;
@end

@implementation Bug

@synthesize longVal,longerVal;

@end


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    unsigned int    ivarCount=0;
    Ivar *ivars= class_copyIvarList([Bug class], &ivarCount);

    for(unsigned int x=0;x<ivarCount;x++) {
        NSLog(@"Name [%@] encoding [%@]",
         [NSString stringWithCString:ivar_getName(ivars[x]) encoding:NSUTF8StringEncoding],
              [NSString stringWithCString:ivar_getTypeEncoding(ivars[x]) encoding:NSUTF8StringEncoding]);
    }

    [pool drain];
    return 0;
}

And here is output from debug console:

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
run
[Switching to process 6048]
Running…
2010-03-17 22:16:29.138 ivarbug[6048:a0f] Name [longVal] encoding [q]
2010-03-17 22:16:29.146 ivarbug[6048:a0f] Name [longerVal] encoding [q]
(gdb) continue

Not a pretty picture!

-- Frank

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about macosx