Skip to content

Error accessing bool #6057

@plgarcia

Description

@plgarcia

When setting bool to true or false, only the lower bit is set to 1 or 0.

But a test compares the full byte.

When for some reason, for example restoring à bool from EEPROM, some of the higher bits of the octet are set to 1, if (mybool) is always true even if the mybool is set to false jut before the test..
There is no way to set this bool to false.

For static variable this happens or not from one version to another, depending probably on what is present in memory at startup.

To solve that, in my software I declared some defines (BOOL uint8_t, TRUE 1, FALSE 0) and do not manipulate bool any longer.
I program on Arduino MEGA 2560

Metadata

Metadata

Assignees

No one assigned

    Labels

    Library: EEPROMThe EEPROM Arduino libraryWaiting for feedbackMore information must be provided before we can proceed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions