Page 1 of 1

Array initialisation - simulation gotcha

Posted: Tue Jul 13, 2021 12:54 pm
by mnfisher
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

Re: Array initialisation - simulation gotcha

Posted: Tue Jul 13, 2021 1:36 pm
by Steve-Matrix
Thanks, Martin. I'll look into that and try to fix it.

Re: Array initialisation - simulation gotcha

Posted: Tue Jul 13, 2021 2:45 pm
by Steve-Matrix
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.