Xcode整数++加4 [英] Xcode integer++ adding 4

查看:108
本文介绍了Xcode整数++加4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xcode项目,其中包含以下代码:

I have an xcode project that's with the following code:

在fflayer.h中

in fflayer.h

int * ffinjar;

int *ffinjar;

fflayer.m

in fflayer.m

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    CGPoint touchLocation = [self convertTouchtoNodeSpace:touch];
    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
    oldTouchLocation = [CCDirector sharedDirector] convertToGL:oldLocation];
    oldTouchLocation = [self convertoToNodeSpace:oldTouchLocation];

    CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
    [self panForTranslation:translation];

    if (CGRectIntersectsRect(selSprite.boundingBox, eJar.boundingBox)) {

    selSprite.userData = FALSE;
    selSprite.visible = FALSE;
    selSprite.position = ccp(winSize.width +40, winSize.height + 40);
    _currentFlies--;
    ffinjar++;

 }

由于某种原因,这导致ffinjar添加4而不是1.但是_currentFlies只是减去1.我不知道。任何人都可以看到我可能做错了吗?

for some reason, this causes ffinjar to add 4 instead of 1. but the _currentFlies just subtracts 1. I have no idea. can anyone see what I may be doing wrong?

推荐答案

这是因为你的声明是一个指针,并且递增指针有一个不同的含义而不是增加一个int(IIRC,它增加sizeof(int),我不确定)。

It's because your declaration is of a pointer, and incrementing a pointer has a different implication than incrementing an int (IIRC, it increments by sizeof(int), by I'm not sure).

int *ffinjar;
// perhaps should be
int ffinjar;

编辑:我做了一个测试,确实增加指针到一个int添加了4在我的系统上(和sizeof(int)也是4)

I have done a test, and indeed incrementing a pointer-to-an-int adds 4 on my system (and sizeof(int) is 4 as well)

这篇关于Xcode整数++加4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆