You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
does not result in the value in first_thing being copied into second_thing, which misled me (an experienced coder) and probably would be very misleading to a novice (common among Arduino users). It in fact appears to cause the checksum of second_thing to become invalid, as evidenced by the constructor reinitializing the default value on the next boot.
Using a temporary variable yields the expected result, e.g.,
...
T temp = first_thing;
second_thing = temp;
...
I suggest that EEPROMStorage<T>::operator=(const EEPROMStorage & rhs) and EEPROMStorage<T>::operator=(const T& rhs)should be equivalent.
The text was updated successfully, but these errors were encountered:
#include <EEPROM-Storage.h>
EEPROMStorage<int> a(0, 0);
EEPROMStorage<int> b(sizeof(int) + 1, 0);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Values at startup: ");
Serial.print("a: "); Serial.println(a);
Serial.print("b: "); Serial.println(b);
}
void loop() {
// put your main code here, to run repeatedly:
a++;
if(a % 5 == 0) {
b = a;
Serial.println("Assigned a to b!");
Serial.println("New values: ");
Serial.print("a: "); Serial.println(a);
Serial.print("b: "); Serial.println(b);
Serial.println("Reset the arduino now.");
while(true) delay(100);
}
}
Actual output:
Values at startup:
a: 0
b: 0
Assigned a to b!
New values:
a: 5
b: 5
Reset the arduino now.
Values at startup:
a: 5
b: 0
Assigned a to b!
New values:
a: 10
b: 10
Reset the arduino now.
Notice that b is reinitialized to 0.
Expected output:
Values at startup:
a: 0
b: 0
Assigned a to b!
New values:
a: 5
b: 5
Reset the arduino now.
Values at startup:
a: 5
b: 5
Assigned a to b!
New values:
a: 10
b: 10
Reset the arduino now.
With intrinsic type
T
, given:Code such as the following:
does not result in the value in
first_thing
being copied intosecond_thing
, which misled me (an experienced coder) and probably would be very misleading to a novice (common among Arduino users). It in fact appears to cause the checksum ofsecond_thing
to become invalid, as evidenced by the constructor reinitializing the default value on the next boot.Using a temporary variable yields the expected result, e.g.,
I suggest that
EEPROMStorage<T>::operator=(const EEPROMStorage & rhs)
andEEPROMStorage<T>::operator=(const T& rhs)
should be equivalent.The text was updated successfully, but these errors were encountered: