-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Bluetooth: Mesh: Use IS_ENABLE replace #if #80659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LingaoM
commented
Oct 31, 2024
- Use IS_ENABLED replace #if defined to make code more readable
- Move adv_tag_to_str to send_pending_adv, since only this used.
subsys/bluetooth/mesh/adv_ext.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure parentheses are not needed here? Ternary operator has lower precedence than bitwise OR: https://en.cppreference.com/w/c/language/operator_precedence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, maybe look preprocessing .i file, i still don't know how to view the .i file compiled by zephyr. But add parentheses always right.
44f76d3 to
01a380c
Compare
1. Use IS_ENABLED replace #if defined to make code more readable 2. Move adv_tag_to_str to send_pending_adv, since only this used. Signed-off-by: Lingao Meng <[email protected]>
01a380c to
68a64e7
Compare
| if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) { | ||
| return &advs[ARRAY_SIZE(advs) - 1]; | ||
| } else { | ||
| return &advs[0]; | ||
| } | ||
| return IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) ? | ||
| &advs[ARRAY_SIZE(advs) - 1] : &advs[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you're a fan of compact code, however I really don't think this improves readability. The C ternary operator is useful in places where you can't use if () however I don't think it improves readability at all (IMO it does the contrary).
| if (!!(CONFIG_BT_MESH_RELAY_ADV_SETS)) { | ||
| return &advs[1]; | ||
| } else { | ||
| return &advs[0]; | ||
| } | ||
| return !!(CONFIG_BT_MESH_RELAY_ADV_SETS) ? &advs[1] : &advs[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, and this is also out of scope of the PR, since it's talking about replacing #if and not if ()
|
IMO the old code was more readable. |