Comparison between pointer and integer

13,951

In your code, charsSinceLastUpdate is a pointer, you need to define it without the *:

int charsSinceLastUpdate = 0;

Unless, of course, you meant to define it as a pointer, in which case you'd need to use the dereference operator to retrieve the value that it's pointing to, like so:

if(*charsSinceLastUpdate >= 36) {
   //...
}
Share:
13,951

Related videos on Youtube

N S
Author by

N S

Updated on June 04, 2022

Comments

  • N S
    N S 7 months

    I'm just learning Cocoa (coming from C#) and I'm getting a strange error for something that seems really simple. (charsSinceLastUpdate >= 36)

    #import "CSMainController.h"
    @implementation CSMainController
    //global vars
    int *charsSinceLastUpdate = 0;
    NSString *myString = @"Hello world";
    //
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    ...
    }
    //other functions
    - (void)textDidChange:(NSNotification *)aNotification {
        NSLog(@"charsSinceLastUpdate=%i",charsSinceLastUpdate);
        if (charsSinceLastUpdate>=36) { // <- THIS line returns the error: Comparison between pointer and integer
            charsSinceLastUpdate=0;
            [statusText setStringValue:@"Will save now!"];
        } else {
            charsSinceLastUpdate++;
            [statusText setStringValue:@"Not saving"];
        }
    }
    //my functions
    - (void)showNetworkErrorAlert:(BOOL)showContinueWithoutSavingOption {
    ...
    }
    //
    @end
    

    Any help would be appreciated, thanks!

  • N S
    N S over 12 years
    Thanks, I thought the * was just a common naming convention

Related