| Author |
Message |
sanjay
Joined: 04 Jul 2003 Posts: 117
|
07 Dec 2003 11:17 Need explanation of C code compilation on ADS , ARM sdt |
|
|
|
|
Hi all,
I jsut wanted to ask this question..
When I declare an array using example like
int arraySize = 5
int array[arraySize] = { ......};
and compile it under ADS1.2 software I dont get any errors but when I try the same thing under ARm SDT evaluation software
it gives an error...
Can anyone help as to why is this so..
or is there any other way in which I can implement the above example without ERRORS in ARM SDT.
basically need something like "int arraySize" that gets the size of the array and then use it in the array declaration... as mention above
I even tried using const keyword but nothing helped..
If I go the pointers route.. how can I implement it..
like say if I have an array . int array[] = {3 , 4 , 5 , 6 , 7};
I know one can step through the array but how can then one detect the end of the array..
Help would be appreciated...
Thanks
|
|
| Back to top |
|
 |
btbass
Joined: 20 Jul 2001 Posts: 1187 Helped: 113 Location: Oberon
|
07 Dec 2003 13:41 |
|
|
|
|
c does not support dynamic arrays so the array size has to be a constant.
You can declare an array like this:
#define arraysize 5
int array[arraysize];
or like this:
int array[] = {1,2,3,4,5};
elements can be accesed like
ix = array[4];
or:
int *p = array;
for(ix = 0; ix < arraysize; ++ix)
{
var1 = *p++;
var2 = *(p+ix);
}
you know the array size so you can check for the end of the array.
|
|
| Back to top |
|
 |
Google AdSense

|
07 Dec 2003 13:41 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
artem
Joined: 22 May 2003 Posts: 1652 Helped: 91 Location: Turan
|
07 Dec 2003 15:01 |
|
|
|
|
| C required that array size must be known at compile time so using #define constant is the most appripriate way to do so . If your array size is not known at compile time , you should use malloc to alloacte memory then map it to desired data type .
|
|
| Back to top |
|
 |