Array initialisation. Size error.
Posted: Wed Aug 16, 2023 7:54 pm
Using a lookup table - I noticed a bug when my code worked in simulation but not on MCU. I used an Arduino Uno here and a 256 word lookup table. In my 'test' program to demonstrate (and to try and pinpoint the error in my main code) - it worked until I added a .return = value statement. Then stack corruption occurs and the program crashes.
Looking at the C code generated - (from constant table[256])
The 2017 is incorrect (and eats all the available RAM)
Changing the table size to 2 gives a generated table size of 14.
It works correctly using variable instead of creating a constant.
As an aside - I initially missed a 0 from a hex number in the lookup (so x0110 instead of 0x0110) this simulated fine but (using 0 for the duff value) but fails to compile.
Similarly I can add a string as a value (say {0x1110, "abc"} - which compiles okay (it's #define data) but is a little odd?
Martin
Looking at the C code generated - (from constant table[256])
Code: Select all
#define FCLsz_TABLE 2017
const MX_UINT16 FCL_TABLE[FCLsz_TABLE] = {0x0000, 0x8005,
Changing the table size to 2 gives a generated table size of 14.
It works correctly using variable instead of creating a constant.
As an aside - I initially missed a 0 from a hex number in the lookup (so x0110 instead of 0x0110) this simulated fine but (using 0 for the duff value) but fails to compile.
Similarly I can add a string as a value (say {0x1110, "abc"} - which compiles okay (it's #define data) but is a little odd?
Martin