What this says to me is that one must pre-initialize the EEPROM if one is expecting a bool because one cannot be certain of the content of the EEPROM. The case I present is one where the initial value is not important, but, I have to massage it on every boot (read it as a uint8_t, extract the LSB and assign it to a bool)
@UKHeliBob suggests I supply the entire code so that appropriate context can be ascertained:
#include <EEPROM.h> // non-volatile memory library
bool b;
bool c;
void t(uint8_t s){
Serial.println(F("--------------------------Testing boolean in NVRAM"));
Serial.print(F("Value placed in NVRAM: "));Serial.println(s);
//b=s;
//Serial.print(F("Value placed in NVRAM: "));Serial.println(b);
EEPROM.put(144,s);
EEPROM.get(144,b);
if (b) {Serial.print("");b = 1; } else {Serial.print("");b = 0;}
//if (b) {b = 1;Serial.print(""); } else {b = 0;Serial.print("");}
//if (b) { b = 1; } else { b = 0;}
c = !b;
Serial.print(F("boolean read from NVRAM: "));Serial.println(b);
Serial.print(F("boolean evaluates as: "));if (b) Serial.println(F("true")); else Serial.println(F("false"));
Serial.print(F("complemented boolean read from NVRAM: "));Serial.println(c);
Serial.print(F("complemented boolean evaluates as: "));if (c) Serial.println(F("true")); else Serial.println(F("false"));
}
void setup() {
Serial.begin(115200);
Serial.println(F("EEPROM and booleans"));
t(128);
t(129);
t(255);
t(1);
t(0);
}
void loop() {}
Now take a look at lines 12, 13 and 14. 12 works, the other two don't. Is this what is meant by unexpected behaviour?