Page 1 of 1

How to initialise the array?

Posted: Sun Sep 17, 2017 5:10 am
by streammaster
Hi Guys,
I couldn't find the answer how to initialize the array in FC7 ( so the simulation not complines as an Error) and not sure if this error would have any influence on the compiler?
The only way which I figure it out so far is by assigning the value it in the calculation block, but this is really painfull exercise as I cannot figure out working syntax apart individual variable (test_array[5][5][2]):

test_array[0][0][0] = 0
test_array[0][0][1] = 0
test_array[0][0][2] = 0
.........
test_array[4][4][1] = 0
So this declaration would have 50 lines :cry:

I would expect that something like this is possible in case all variables are 0:
test_array = {0} or test_array[]={0}

Making the loop is another option which I will do in the desperation, but only if there is no other (proper) way.
I would expect that it should be 'automatically' initialized as '0' if the variable is global and if is not declared differently.

Could you please provide some more details how to do it in FC7 and how this is passed to the c code and to the PIC18 compiler?

Regards,

Igor

Re: How to initialise the array?

Posted: Sun Sep 17, 2017 1:09 pm
by johnsondav
Hi Igor
The way I understand the way to set up an array is as follows:
array.jpg
array.jpg (171.84 KiB) Viewed 2991 times
When the variable is declared, I place the size of the array using [ ] as you have within the set up box shown above.
Each value can then be defined using the calculation icon.

Hope this helps.

Regards
Dave

Re: How to initialise the array?

Posted: Mon Sep 18, 2017 10:42 am
by Benj
I think the easiest way for a large array is to have a loop or nested loop for multi dimensional arrays.

For example TestArray[10]

Code: Select all

index = 0
while (index < 10)
{
  TestArray[index] = 0
  index = index + 1
}
For example TestArray[10][10]

Code: Select all

index = 0
while (index < 10)
{
  index2 = 0
  while (index2 < 10)
  {
     TestArray[index][index2] = 0
     index2 = index2 + 1
  }
  index = index + 1
}