Cast Var to Function

I am trying to get the following function to work but the compiler is giving the following error:

Does anyone have an idea what this means or how to fix?

flashStorage.cpp: In function 'void readFromMemory8_8(uint8_t&, uint8_t)':
flashStorage.cpp:829:31: error: invalid initialization of non-const reference of type 'unsigned char*&' from an rvalue of type 'uint8_t* {aka unsigned char*}'
     flash->read(&data, address);
const static uint8_t startSlotAdr = 52;
uint8_t startSlot = 1;

readFromMemory8_8(startSlot, startSlotAdr); // data, address

void readFromMemory8_8(uint8_t &data, uint8_t address) {
  #if PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION
    EEPROM.get(address, &data);
  #elif PLATFORM_ID == PLATFORM_P1
    flash->read(&data, address);
  #endif
}

Excuse my ignorance if it’s valid, but I’ve never seen a &varname as a function parameter.

I would have done:

void readFromMemory8_8(uint8_t *data, uint8_t address)

In which case the EEPROM line would be:

EEPROM.get(address, *data);

I don’t know where flash->read is defined but assuming it takes a pointer as the first parameter it would then be:

flash->read(data, address);

And the calling line becomes:

readFromMemory8_8(&startSlot, startSlotAdr);
1 Like

The EEPROM.get function takes a reference to a variable, not a pointer to a variable, so it should be:

EEPROM.get(address, data);
3 Likes