CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pcb compiler is treating some functions like macros

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pgomolchuk



Joined: 20 Feb 2009
Posts: 3

View user's profile Send private message

pcb compiler is treating some functions like macros
PostPosted: Fri Feb 20, 2009 5:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 20, 2009 5:11 pm     Reply with quote

One solution: Use a "wrapper" function.
http://www.ccsinfo.com/forum/viewtopic.php?t=23844
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Feb 20, 2009 6:12 pm     Reply with quote

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

View user's profile Send private message

pcb compiler is treating some functions like macros
PostPosted: Fri Feb 20, 2009 6:15 pm     Reply with quote

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

View user's profile Send private message

pcb compiler is treating some functions like macros
PostPosted: Fri Feb 20, 2009 6:17 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 20, 2009 9:05 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 20, 2009 11:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 20, 2009 11:39 pm     Reply with quote

You're the only one of us that noticed that. (And we should have).
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 20, 2009 11:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 21, 2009 6:18 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group