electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Need explanation of C code compilation on ADS , ARM sdt


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Need explanation of C code compilation on ADS , ARM sdt
Author Message
sanjay



Joined: 04 Jul 2003
Posts: 117


Post07 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


Post07 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
Google Adsense




Post07 Dec 2003 13:41   

Ads




Back to top
artem



Joined: 22 May 2003
Posts: 1652
Helped: 91
Location: Turan


Post07 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
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Need explanation of C code compilation on ADS , ARM sdt
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
SONY SDT-5000 ; SDT-7000 ; SDT-9000 ; SDX-300C ; SDX-45V ; (3)
Need explanation for startup files in ARM software (1)
c code problem - need explanation of errors (3)
new in programming microcontroller- need explanation of code (1)
Need help with ARM ADS 1.2 (2)
Convert GCC ARM to ADS ARM C source. (4)
ADS EXPLANATION (3)
Ignoring part of verilog code during compilation (2)
Need Help for arm code developemnt (2)
Need example ASM code for ARM (5)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS