Skip to content

bitWrite macro incorrectly expands ternary operator #14

Open
@agdl

Description

@agdl

From @svatoun on December 13, 2016 8:34

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)

Copied from original issue: arduino/Arduino#5714

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions