Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparison between point and integer ('int' and 'void *') using NULL

I get the error message "Comparison between point and integer ('int' and 'void *') using NULL" before I run the application. The strange thing is the application runs perfect every time. Here is a snippet of the code.

- (IBAction) addButtonAction:(id)sender
{
    int timeStamp = nil;

    timeStamp = self.hourTextField.intValue;


    if (timeStamp == NULL) {
        NSLog(@"Nothing here for ya");
    }
    else {
        NSLog(@"monkey shit");
    }

}

I get the error at the line.

    if (timeStamp == NULL) {
like image 938
rjm226 Avatar asked Nov 30 '25 16:11

rjm226


1 Answers

NULL is meant to be used for pointer comparisons only. timeStamp is an int, not a pointer, so the comparison doesn't really make sense. The compiler sees the comparison with NULL and says, "maybe he thinks timeStamp is a pointer, but it's not, so I better warn him". In this case, you probably want to check that timeStamp is not zero:

if (timeStamp == 0) {
    NSLog(@"Nothing here for ya");
}

Indeed, that's actually what your code is doing now, because in reality NULL is 0.

Also worth noting is that the compiler is issuing a warning, not an error. The important difference is that warnings are things the compiler thinks might be a mistake, but which don't prevent the program from compiling. Errors actually prevent the compiler from doing its job, and cause compilation to fail. You should never ignore warnings. You can tell the compiler to treat warnings as errors, to enforce discipline on yourself.

like image 105
Andrew Madsen Avatar answered Dec 02 '25 07:12

Andrew Madsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!