EEPROM data order

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have some data items assigned to the EEPROM section. I noticed that the order in which they are allocated space in EEPROM varies depending on whether or not they are initialized.

Case 1:

uint8_t dataA __attribute__ ((section (".eeprom")));
uint16_t dataB __attribute__ ((section (".eeprom")));

dataA is assigned address 0 with dataB at address 1.

Case 2:

uint8_t dataA __attribute__ ((section (".eeprom"))) = 0;
uint16_t dataB __attribute__ ((section (".eeprom"))) = 0;

dataA is assigned address 2 with dataB at address 0.

Any ideas why this might be and is there any way to get the order to be consistent?

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Last Edited: Thu. Apr 26, 2018 - 07:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ordering is at the compiler's and linker's discretion.

The only way to get a guaranteed order is to use a single large
struct holding all the values.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

Topic locked