0

This seems like a recurring question/issue but I did not manage to solve it as I am new to C++ and pointers/references.

Here is my setup :

uint16_t API_PORT = 0;

I then feed that variable with data retrieved from an EEPROM as follows :

i2cReadShortFromExternalEEPROM(I2C_ADDR_EEPROM, (addrAPI + sizeof(API_HOSTNAME) + 1), API_PORT);

my function is :

void i2cReadShortFromExternalEEPROM(int i2cAddressOfExternalEEPROM, unsigned int atAdress, short *s) {
  byte firstByte = i2cReadByteFromExternalEEPROM(i2cAddressOfExternalEEPROM, atAdress);
  byte secondByte = i2cReadByteFromExternalEEPROM(i2cAddressOfExternalEEPROM, atAdress + 1);

  s = ((short)firstByte << 8) + (short)secondByte;
}

This throws following error at compilation :

exit status 1
invalid conversion from 'uint16_t' {aka 'short unsigned int'} to 'short int*' [-fpermissive]
Musa
  • 1,334
  • 1
  • 11
  • 21

1 Answers1

0

Your function is expecting a "short int*", so a pointer.

This is what you have defined in the signature of the function:

void i2cReadShortFromExternalEEPROM(int i2cAddressOfExternalEEPROM, unsigned int atAdress, short *s) . See the "short* s" at the end. That is a ponter.

You are handing over a "short" value, not a pointer: "API_PORT" is not a pointer.

So, you need to take the address of "API_PORT" with the &-operator.

Something like:

i2cReadShortFromExternalEEPROM(I2C_ADDR_EEPROM, (addrAPI + sizeof(API_HOSTNAME) + 1), &API_PORT);

That is all which I can see from this code snippet . . .

A M
  • 14,694
  • 5
  • 19
  • 44