Page 1 of 1

Declaration of an array

Posted: Mon Nov 08, 2010 7:17 pm
by Spanish_dude
Hi everyone,

I just wanted to know the difference between a global array and local array on microcontrollers.
I tried to create an array of 82 bytes within the main, but the compiler (mikroC compiler, not tried on flowcode) tells me that there isn't enough memory, but creating that same array as global (outside main) does compile perfectly.

I'm just curious about why it compiles when it's a global array and why it doesn't when it's a local ?

Thanks,

Nicolas Lopez F.

Re: Declaration of an array

Posted: Tue Nov 09, 2010 9:43 am
by Benj
Hello,

I've never used the mikroC compiler so I can't say for sure but maybe there is some wierd kind of paging going on where the compiler is trying to fit each function into a single page of memory? With Microchips C18 compiler you have to specify if the code is going to go into an alternate page or the code simply does not work but does not give you a warning or an error. I have not seen this problem in the BoostC or HiTech compilers :)

Re: Declaration of an array

Posted: Tue Nov 09, 2010 9:19 pm
by Spanish_dude
Ok, thanks for clarifying that ^^

Re: Declaration of an array

Posted: Wed Nov 10, 2010 2:00 pm
by Benj
The Microchip C18 compiler does the allocation using pragma commands like this.

#pragma udata1
#pragma udata2
#pragma code

The udata1 and udata2 sections contain global variables and the code section contains the functions for the program.

Re: Declaration of an array

Posted: Thu Nov 11, 2010 1:28 pm
by Spanish_dude
Thx, but I'll use Flowcode :P
It's easier with it.
:mrgreen: