Skip to content

bitWrite macro incorrectly expands ternary operator #5714

Closed
@svatoun

Description

@svatoun

let's have a bitWrite(data, bitIndex, computedValue == 5 ? 1: 0);

bitWrite macro definition lacks parenthesis around the `bitvalue' parameter, so it expands as follows

(computedValue == 5 ? 1 : 0 ? bitSet(value, bit) : bitClear(value, bit))

and the `0 ? bitSet...' is then compiled as the false branch of the ternary operator in the passed expression.
Please correct the definition as follows:

#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))

(parenthesis added)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Architecture: AVRApplies only to the AVR microcontrollers (Uno, etc.)Architecture: SAMApplies only to the SAM microcontrollers (Due)Architecture: SAMDApplies only to the SAMD microcontrollers (Zero, etc.)Type: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions