I notice an oddity in array initialisation in simulation.
Say I have an array x[5] of byte initialised to {0,1,2,3,4} - this works correctly at runtime (on MCU) and in simulation.
However if I use hex:
x[5] initial value {0x01, 0x02, 0x03, 0x04, 0x05}
In simulation this acts as {0,0,0,0,0}.
(Only hex values treated as 0 - so {0x10, 2,3,4, 0x05} = {0, 2, 3, 4, 0})
Compilation is correct
Martin
Array initialisation - simulation gotcha
-
- Valued Contributor
- Posts: 1628
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
-
- Matrix Staff
- Posts: 1548
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 214 times
- Been thanked: 362 times
-
- Matrix Staff
- Posts: 1548
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 214 times
- Been thanked: 362 times
Re: Array initialisation - simulation gotcha
A quick update on this...
I've fixed it so that integer array initialisers with hex, binary and character elements will correctly set initial values in simulation and deployed App Developer projects, so an initialiser like this...
{ 12, 0x20, 'X', 0b101 }
...will produce the following decimal initial values in the array...
{ 12, 32, 88, 5 }.
I also noticed that a floating point array would only simulate correctly with integer initialisers, so I have fixed this so you can initialise a floating point array with floating point and/or integer values.
These fixes will be available in the forthcoming v9.2 release which should be out in the next week or so.
I've fixed it so that integer array initialisers with hex, binary and character elements will correctly set initial values in simulation and deployed App Developer projects, so an initialiser like this...
{ 12, 0x20, 'X', 0b101 }
...will produce the following decimal initial values in the array...
{ 12, 32, 88, 5 }.
I also noticed that a floating point array would only simulate correctly with integer initialisers, so I have fixed this so you can initialise a floating point array with floating point and/or integer values.
These fixes will be available in the forthcoming v9.2 release which should be out in the next week or so.