Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need explanation of C code compilation on ADS , ARM sdt

Status
Not open for further replies.

sanjay

Full Member level 1
Joined
Jul 4, 2003
Messages
98
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,012
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
 

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.
 

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 .
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top