View Full Version : Pre-Load Arrays in EasyC, Possible?
Chris_Elston
13-02-2006, 11:22
Can anyone tell us if it is possible to pre-load your array with constant values in easyC? We want to create a lookup table and just need to create a single dimension array and load it with constants.
We have tried to define the constants as show in the screen shot. Look at "power[3]" It's a 1 x 4 array and when we set the value field to something like 0,0,0,0 we get an Error: 1 when we try and compile this.
If we leave it value field blank, such as the variable "sign[3]" then it will compile just fine.
We have tried formatting the value field:
0,0,0,0
{0,0,0,0}
(0,0,0,0)
The only thing that seems to work is leave it blank, then in code somewhere we have to do this:
power[0] = value0
power[1] = value1
power[2] = value2
power[3] = value3
(or write a loop to load up several constants...)
Is this the only way to pre-load the arrays in EasyC?
Mark McLeod
13-02-2006, 11:55
I haven't focused any attention on EasyC, so take this with a grain of salt.
But from a C perspective...
power[3] in C has three locations available not four.
You may be confusing this with the index which starts with zero.
Initializing it with 3 values should work, i.e., {0,0,0}, or use power[4] instead.
In your example of setting the values at runtime you are actually overwriting the memory location past the end of the power array. The compiler doesn't check for this (there are other commercial tools that perform that function).
You can actually do something like "power[99] = 1;" and the program won't complain, but some other part of your code may mysteriously start acting erratically.
Chris_Elston
13-02-2006, 11:58
Yes, your right, hadn't had my mountain dew yet when I was trying to "make-up" a question to post.
Let me rephrase it:
We have tried formatting the value field:
0,0,0
{0,0,0}
(0,0,0)
The only thing that seems to work is leave it blank, then in code somewhere we have to do this:
power[0] = value0
power[1] = value1
power[2] = value2
***Thanks Mark***
Either way...stilll doesn't seem to work.....
Get an ERROR:1 when we compile it.
EDIT....well that was funny! It seems to work now.
Just now tried this format:
{0,0,0} with a power[3]
And it seems to work now. Geez..I need to go lay down....Maybe it's our programming computer at the robot field....works fine on my laptop.
BTY: As awesome as the HELP FILE is in EasyC, this is not documented how to do this in the help file. FYI....
-
Mark McLeod
13-02-2006, 12:04
Geez..I need to go lay down....Maybe it's our programming computer at the robot field....works fine on my laptop.
Just double your intake of Mountain Dew. Time enough for sleep after ship.;)
I did notice that the {1,2,3,4} format does work but it generates an error (stack) if you have more than 100 or so. We were trying to generate a motor speed lookup table of 255 entries.
Chris_Elston
21-02-2006, 21:04
Ours worked too until about {1,2,3,4, .... 51} At 51...we got an error. We needed about 70 slots to fine tune our lookup table as well. We ended up loading the array manually as described above.
-
Kingofl337
22-02-2006, 10:25
The compiler only allows for 120 int slots total and allows for 254 char slots total. Not, 120/254 per array.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.