작은 문제가 있습니다. objective-c 함수에서 c-function으로 전달할 때 배열 및 크기가 변경되었습니다.목표 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입니다.
감사합니다.
관련 사항 : http://stackoverflow.com/questions/720077/calculating-size-of-an-array – whunmr