orgua / OneWireHub

OneWire slave device emulator
GNU General Public License v3.0
343 stars 86 forks source link

Writing array in to constexpr uint8_t array #100

Open x225am opened 3 years ago

x225am commented 3 years ago

Hi All, I am trying to store array data in to a constant array. Is it possible? In the examples in the DS2431 example we have this: constexpr uint8_t mem_dummy[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; An I would like to use data which I read from Arduino internal eeprom (or external i2c epprom) stored in the data array For example I have:

byte ReadData[8]; // this I am reading from internal eeproom ReadData[0]=0xAA; ReadData[1]=0xAB; ReadData[2]=0x10; ReadData[3]=0x11; ReadData[4]=0xBC; ReadData[5]=0xBF; ReadData[6]=0xCD; ReadData[7]=0x2D;

constexpr uint8_t mem_dummy[] = {ReadData[0], ReadData[1], ReadData[2], ReadData[3], ReadData[4], ReadData[5], ReadData[6], ReadData[7]};

In this case after compilation I have next error on the compiler: the value of 'ReadData' is not usable in a constant expression

Any way around it? Thanks in advance.

rikka0w0 commented 2 years ago

Just remove the 'constexpr' qualifier.