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).
我发现我认为可能是Ivar和Objective-C运行时的错误。我正在使用XCode 3.2.1和相关库,在X86_64(MacBook Pro)上开发64位应用程序。
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').
我希望下面的“longVal”的类型编码为'l',Ivar编码显示'q'(这是'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
- 弗兰克
2 个解决方案
#1
2
It's not a bug. The GCC compiler, under a 64 bits architecture, chooses to represent long
s as 64 bit integers. You can check it yourself:
这不是一个错误。在64位架构下,GCC编译器选择将long表示为64位整数。你可以自己检查一下:
printf("%lu\n", sizeof(long)); // will give "8"
As a reminder, the C standard only defines minimum sizes for integer types. long
is only guaranteed to be at least 32 bits.
提醒一下,C标准仅定义整数类型的最小大小。 long仅保证至少为32位。
#2
0
Mac OS X, Linux and most other 64-bit operating systems use the LP64 model, where longs and pointers are 64 bits, while ints are 32 bits.
Mac OS X,Linux和大多数其他64位操作系统使用LP64模型,其中long和指针是64位,而int是32位。
#1
2
It's not a bug. The GCC compiler, under a 64 bits architecture, chooses to represent long
s as 64 bit integers. You can check it yourself:
这不是一个错误。在64位架构下,GCC编译器选择将long表示为64位整数。你可以自己检查一下:
printf("%lu\n", sizeof(long)); // will give "8"
As a reminder, the C standard only defines minimum sizes for integer types. long
is only guaranteed to be at least 32 bits.
提醒一下,C标准仅定义整数类型的最小大小。 long仅保证至少为32位。
#2
0
Mac OS X, Linux and most other 64-bit operating systems use the LP64 model, where longs and pointers are 64 bits, while ints are 32 bits.
Mac OS X,Linux和大多数其他64位操作系统使用LP64模型,其中long和指针是64位,而int是32位。