user1415635
user1415635

Reputation: 3

Xcode integer++ adding 4

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

in fflayer.h

int *ffinjar;

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++;

 }

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?

Upvotes: 0

Views: 244

Answers (1)

Chris Trahey
Chris Trahey

Reputation: 18290

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;

EDIT: 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)

Upvotes: 1

Related Questions