View previous topic :: View next topic |
Author |
Message |
pgomolchuk
Joined: 20 Feb 2009 Posts: 3
|
pcb compiler is treating some functions like macros |
Posted: Fri Feb 20, 2009 5:04 pm |
|
|
Hi,
I am compiling for a pic10f202. I noticed that under certain circumstances, my function calls are being treated more like macros. For instance, in certain cases I have a function foo() which takes 50 bytes. The sequence
foo();
foo();
foo();
foo();
causes 4 COPIES of this function to appear in program space, consuming 4x50=200bytes.
Curiously, if i have a function bar() that is behaving correctly, i.e
bar();
bar();
bar();
bar();
results correctly in 4 calls to the SAME function in program space, but I put one foo() call afterward, it causes bar() to have the same problem, i.e
bar();
bar();
bar();
bar();
foo();
now causes bar() to appear 4 times in program space like foo() did!
Does anyone know under what circumstances the compiler is doing this? I can provide more detail if required.
Thanks,
Patrick |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Feb 20, 2009 6:12 pm |
|
|
For user functions, the compiler shouldn't do that unless you specify #inline before the respective function. Or there must be a particular condition, I'm not aware of.
Can you make a minimal example that causes the said behaviour? Perhaps you already learn about the reason, when trying this, otherwise other forum members can try to understand the issue. The manual tells, that insufficient stack space may be a reason, see #SEPARATE doc. But I can't see a relation to your code, may be if the function call has more parameters.
Last edited by FvM on Fri Feb 20, 2009 6:16 pm; edited 1 time in total |
|
|
pgomolchuk
Joined: 20 Feb 2009 Posts: 3
|
pcb compiler is treating some functions like macros |
Posted: Fri Feb 20, 2009 6:15 pm |
|
|
Thanks for the reply.
It will not work. My wrapper function now merely contains the same 4 instances.
This is all my own code, no library calls. I don't understand why placing the foo() call underneath the 4 bar() calls makes the compiler change it's mind and paste 4 bar() calls like macros.This behaviour is contrary to the whole notion of a function.
If I can understand under what circumstances the compiler is doing this I may find a solution.
Regards,
Patrick |
|
|
pgomolchuk
Joined: 20 Feb 2009 Posts: 3
|
pcb compiler is treating some functions like macros |
Posted: Fri Feb 20, 2009 6:17 pm |
|
|
FvM wrote: | For user functions, the compiler shouldn't do that unless you specify #inline before the respective function. Or there must be a particular condition, I'm not aware of.
Can you make a minimal example that causes the said behaviour? Perhaps you already learn about the reason, when trying this, otherwise other forum members can try to understand the issue. |
Hi yes I will make a minimal demonstration, and post it. Thanks for your reply.
Patrick |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Feb 20, 2009 9:05 pm |
|
|
If your function is taking parameters by reference, then I've noticed that the compiler will always inline the function. I solved that by changing the references to pointers. _________________ Andrew |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Fri Feb 20, 2009 11:28 pm |
|
|
pgomolchuk,
The PIC10F2xx processors have a call stack of ONLY TWO LEVELS.
The PCB compiler duplicates your functions because it detects that you need more than two call nesting levels.
Same holds true for PCM for PIC16Fxxx processors if you use more than 8 nesting levels. _________________ Every solution has a problem. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 20, 2009 11:39 pm |
|
|
You're the only one of us that noticed that. (And we should have). |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Fri Feb 20, 2009 11:50 pm |
|
|
This is one of the main features that made me choose CCS compilers more than 10 years ago. _________________ Every solution has a problem. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Feb 21, 2009 6:18 am |
|
|
The said comment with #SEPARATE directive suggests something like this. But I wasn't aware of the low PIC12 stack. So the solution is probably to inline some lower level functions. |
|
|
|