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

SEPARATE & INLINE procedures

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



Joined: 23 Jul 2006
Posts: 20

View user's profile Send private message

SEPARATE & INLINE procedures
PostPosted: Mon Apr 02, 2007 2:31 am     Reply with quote

Hi all,
what is #separate directive.When it is useful and why not it is called like a conventional procedure.?
Ttelmah
Guest







PostPosted: Mon Apr 02, 2007 8:59 am     Reply with quote

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

View user's profile Send private message

thanx
PostPosted: Mon Apr 02, 2007 9:09 am     Reply with quote

thnx a lot...
3dfx



Joined: 24 Mar 2007
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 1:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 1:12 pm     Reply with quote

Also read this thread about a warning if you use #separate:
http://www.ccsinfo.com/forum/viewtopic.php?t=27717&highlight=seperate+stack
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