5
votes

I just inherent a new app from a previous programmer and keep on running into a "Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'bool *') from 'BOOL' (aka 'bool') ".

Code like such as

_backButtonPressed = YES;

_isEdited = YES;

come up with the same error. I tried *(_backButtonPressed) = YES; and *_backButtonPressed = Yes, but both scenarios crashes the program.

Program still work if I leave it alone, but I wanted to keep the code clean. Any suggestion?

1
Does _backButtonPressed need to be a pointer to a BOOL? Can it just be a BOOL? - mipadi
I'm not sure. I wasn't the original programmer. - Coder

1 Answers

10
votes

My guess is that the two variables in question were declared incorrectly. For example, _backButtonPressed is probably declared as

BOOL* _backButtonPressed;

but should be

BOOL _backButtonPressed;

The crash occurs because _backButtonPress is not a pointer: if it was, there would be a statement like _backButtonPressed = (BOOL*)malloc(sizeof(BOOL)); somewhere. If this was not done before you try to assign to *(_backButtonPressed), then you will see a crash.

It is easy to make the mistake of declaring BOOL* instead of BOOL, because Cocoa objects are always declared with the *

I recommend that you fix the declarations. I am pretty sure everything will work if you do that.