Jcfunk Jcfunk - 1 year ago 66
Android Question

GCC 6.3 warning comparison of constant '0' with Boolean expression is always false

The warring points to this bit of code

#define DO_SAFE(do_work, goto_error) \
DO_IF(unlikely((do_work) < 0), goto_error)

This is from a header file. I don't understand what this code is trying to do, or compare. To me is seems like do do_work if false then goto error. But if that was correct would it be

(do_work != 0)

but that is just a guess.

Please tell if more info is need.

Function giving error in c file

for (page_num = 0; page_num < PAGE_MAX_NUM; page_num++) {
DO_SAFE(touch_i2c_write_byte(client, PAGE_SELECT_REG, page_num), error);

for (u_address = DESCRIPTION_TABLE_START; u_address > 10; u_address -= sizeof(struct function_descriptor))
DO_SAFE(touch_i2c_read(client, u_address, sizeof(buffer), (unsigned char *)&buffer) < 0, error);

Answer Source

Oh, I see the problem (if I scroll horizontally — the lines are rather long):

DO_SAFE(touch_i2c_read(client, u_address, sizeof(buffer), (unsigned char *)&buffer) < 0, error);

You're testing a < 0 condition in the macro invocation, which means you end up with the expansion of DO_SAFE doing:

if ((touch_i2c_read(…) < 0) < 0)

and the result of the inner condition never is less than zero.


DO_SAFE(touch_i2c_read(client, u_address, sizeof(buffer), (unsigned char *)&buffer), error);

(That has eliminated the < 0 in your direct invocation of DO_SAFE, leaving the macro to test for < 0.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download