我遇到了一个小问题。从一个objective-c函数传递给c函数时,我得到一个数组并且它的大小发生了变化。Objective 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
为什么在方法2种不同的大小?
在[test]方法中,返回大小始终为4,而不取决于数组的原始大小。
谢谢。
相关: http://stackoverflow.com/questions/720077/calculating-size-of-an-array – whunmr 2010-01-02 19:47:46