Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

ImageCraft Compiler Unable to Compare Null Function Pointers with Zero – KBA88325

ImageCraft Compiler Unable to Compare Null Function Pointers with Zero – KBA88325

Anonymous
Not applicable
Version: **

 

Question: When a function pointer with a null value is compared with zero in the PSoC® 1 ImageCraft compiler, the result of the comparison is false—that is, if pTask is a function pointer with a null value, then the condition ((pTask) != 0) reports true, which is an unexpected operation. Is there any way to overcome this?

 

Answer:

There is an issue with the ImageCraft compiler while comparing null pointers with zero.

However, the following workaround can be used—that is, typecasting the pointer to an integer variable, and then using it to compare with 0, as described below.

Replace the following code snippet:

if (pTask) != 0) { // some tasks }

with this code snippet:

unsigned int i=0; . . i = (unsigned int)pTask; if (i != 0) { //Implies pointer is not NULL. Do operations accordingly }

In the preceding workaround, note that apart from typecasting the pointer variable as an unsigned integer value, you must also assign the typecasted value to an integer variable before performing the compare operation.

0 Likes
284 Views
Contributors