View previous topic :: View next topic |
Author |
Message |
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
Function too Large - Main (?) |
Posted: Tue May 24, 2016 6:40 pm |
|
|
HI all,
I run into this error message from time to time, and usually when I have a deadline to meet at work! Ive seen this come up with the ROM only at 35% sometimes, making it a real enigma. it prevents the program from compiling.
So here are my questions on this issue, Id like your thoughts on any of them if possible:
-- IS there a maximum size for Main or any other function if you are not limited by program space (ROM) ?
-- Is there a way around this If I encounter it while programming?
-- Can this be CHANGED to a higher limit?
-- is there a way to monitor the size of main so I can see this limit coming?
Right now I usually have to cut blocks of program out and make them a separate function, move it out of main and that works. For a while anyway...
Im using windows XPpro, and version PCW version 5.036
Chris |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue May 24, 2016 7:14 pm |
|
|
1- what sort of program rom / main() size are we talking about?
2- is there a time domain reason all the code is in main?
It must make for some interesting looking, fun to trace code.
3- do you merge library code directly into main() too? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1351
|
Re: Function too Large - Main (?) |
Posted: Tue May 24, 2016 7:39 pm |
|
|
In general large all in one main's are a bad idea for a variety of reasons.
Arizona Chris wrote: |
-- IS there a maximum size for Main or any other function if you are not limited by program space (ROM) ?
|
The C standard does not define one, so theoretically no. However, various implementations have physical limits and it isn't just ROM size that affects that. The ability (or lack of) to cross page boundaries and how big pages are sized are just some of the other considerations.
Arizona Chris wrote: |
-- Is there a way around this If I encounter it while programming?
|
Break your program into functions. The is the appropriate way.
Arizona Chris wrote: |
-- Can this be CHANGED to a higher limit?
|
I have never seen an option to personally, but this is technically an implementation defined characteristic.
Arizona Chris wrote: |
-- is there a way to monitor the size of main so I can see this limit coming?
|
Check the assembly/LST file, the SYM file, and the Hex file. Between the 3 you can tell how big the main is getting. Then compare with appropriate datasheets/technical documents. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue May 24, 2016 9:33 pm |
|
|
With PICs all functions including main() have to fit on a memory page. Several small functions may fit on one page but no function can cross a page boundary. If your chip has 4 ROM pages then no function can be bigger than 25% of ROM. Generally many small functions are easier for the compiler to fit on the pages. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
Main too large? |
Posted: Thu May 26, 2016 1:26 pm |
|
|
Thanks Guys, I agree it is proper coding practice to use sub functions in main and not try to fit your entire program into one function. Our company policies on this are pretty standard, writing code in defined blocks as function makes it far easier for the next guy to understand and change!
I think the code crossing boundry for a main function is probably what I see occasionally. the latest one I saw this in had lots of big numbers in main ("magic numbers") that probably filled the space up without realizing it.
The more I am in tune with this program structure, the more efficient I can be in creating the best code for our line of products. Thanks again for your responses, its always a learning experience and so much fun!
Chris |
|
|
|