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.
Declaration of an array
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
- 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
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.
#pragma udata1
#pragma udata2
#pragma code
The udata1 and udata2 sections contain global variables and the code section contains the functions for the program.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact: