【发布时间】:2010-01-02 19:41:08
【问题描述】:
我有一个小问题。我有一个数组,当从 Objective-C 函数传递给 C 函数时,它的大小会发生变化。
void test(game_touch *tempTouches)
{
printf("sizeof(array): %d", sizeof(tempTouches) );
}
-(void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event
{
game_touch tempTouches[ [touches count] ];
int i = 0;
for (UITouch *touch in touches)
{
tempTouches[i].tapCount = [touch tapCount];
tempTouches[i].touchLocation[0] = (GLfloat)[touch locationInView: self].x;
tempTouches[i].touchLocation[1] = (GLfloat)[touch locationInView: self].y;
i++;
}
printf("sizeof(array): %d", sizeof(tempTouches) );
test(tempTouches);
}
控制台日志是:
[touchesEnded] sizeof(array): 12
[test] sizeof(array): 4
为什么两种方法的大小不同?
在 [test] 方法中,返回大小始终为 4,与数组的原始大小无关。
谢谢。
【问题讨论】:
标签: iphone objective-c cocoa-touch