Declaration of an array

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Declaration of an array

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Declaration of an array

Post 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 :)

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Declaration of an array

Post by Spanish_dude »

Ok, thanks for clarifying that ^^

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Declaration of an array

Post 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.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Declaration of an array

Post by Spanish_dude »

Thx, but I'll use Flowcode :P
It's easier with it.
:mrgreen:

Post Reply