|
|
View previous topic :: View next topic |
Author |
Message |
ryan.reeve
Joined: 23 Jul 2006 Posts: 20
|
SEPARATE & INLINE procedures |
Posted: Mon Apr 02, 2007 2:31 am |
|
|
Hi all,
what is #separate directive.When it is useful and why not it is called like a conventional procedure.? |
|
|
Ttelmah Guest
|
|
Posted: Mon Apr 02, 2007 8:59 am |
|
|
It is called 'like a conventional proceedure'...
When you declare a function:
Code: |
int fred(int val) {
//code
}
|
There is an 'overhead' associated with doing this (both in terms of code space, and speed). The value(s) passed to the function, have to be put into 'scratch' memory, then the function called, and the return value passed 'back' in the scratch area, and then passed to the required variables in the calling function. Hence the compiler will, if a routine is short, and only called a few times, instead 'inline' the code, actually putting code for the routine 'into' the calling routine, and saving this overhead. You can force this behaviour to not happen, by declaring the routine like:
Code: |
#separate
int fred(int val) {
//code
}
|
This becomes essential on the older PICs, to prevent the calling routine, from becoming too large, and overflowing a bank.
You can also override the other way (and force code to be physically placed 'inline'), by declaring the routine to be #inline. The only reasons for this, are first speed (this is why the compiler will default to this behaviour), so for a routine that is too large for the default behaviour to be relied on, you might want to force a time critical routine to be 'inline', and secondly to save stack space (if you are close to using all the possible stack entries, forcing a routine 'inline', will save a stack entry).
#inline, and #separate routines, are called exactly like 'normal' routines (and indeed some of your 'normal' routines will be 'inline', while others will be 'separate'). The declaration simply allows _you_ to take control of the behaviour.
Best Wishes |
|
|
ryan.reeve
Joined: 23 Jul 2006 Posts: 20
|
thanx |
Posted: Mon Apr 02, 2007 9:09 am |
|
|
thnx a lot... |
|
|
3dfx
Joined: 24 Mar 2007 Posts: 6
|
|
Posted: Mon Apr 02, 2007 1:10 pm |
|
|
is there any compiler version which allows using both #inline and #asm to gether? i need write some asm code in (#)inlined function. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|