----- Original Message ----- From: Ned Konz To: Sent: Monday, April 21, 2003 5:48 PM Subject: Re: [PIC]: What is difference between #SEPARATE and #INLINE?? > On Monday 21 April 2003 09:36 am, Mccauley, Daniel H wrote: > > > > I see #SEPARATE and #INLINE directives used for functions in > > > > various example C programs i see on the internet. > > > > Could someone explain why these are used and what they actually > > > > do??? > > > > > > These are non-standard directives that tell the compiler to > > > either ensure that the function is called normally (#separate) or > > > expanded inline every time it's called (#inline). > > > > > > The compiler has a particular optimization that will > > > automatically inline functions below a certain size (possibly > > > with other limitations); this is why you need #separate (to put > > > things back to the default situation). > > > > Yes, i do realize that, but what exactly does that mean in layman's > > terms?? And what are the benefits / > > disadvantages for both? When would you use one over the other? > > Advantages of SEPARATE: > * smaller code (only one copy) > * can put breakpoint in it (only one copy) > > Advantages of INLINE: > * faster (omits CALL/RETURN) > Actually, with inlining it is possible to generate smaller code even when using multiple copies of a function. This is because the actual parameters to a function are known and specific optimisation can be performed in situ. Inlining is not just about removing the call and return instructions. This is all highly dependent on the compiler used. This is an example of an XCSB inlined function and specific optimisation: proc inline ubyte FRED(ubyte *xarr) return xarr[3] + xarr[7] endproc proc main() ubyte arr[10] FRED(&arr) endproc here the code generated to use the array inline is a fraction of what it would have been if the function had not been inline. Note that instead of wasting RAM to hold the address of the array (the pointer), adding extra instructions to initialise the pointer, adding more instructions to dereference the pointer (get the value at xarr[3] and xarr[7]), the addresses of the values required are calculated at compile time and used directly. movf arr+3,w addwf arr+7,w movwf result without inlining the compiler would have produced movf xarr+1,w movwf xacc1+1 movf xarr+0,w addlw 3 btfsc STATUS,C incf xacc1+1 movwf FSR bcf STATUS,IRP btfsc xacc1+1,0 bsf STATUS,IRP movf INDF,w movwf xacc1 movf xarr+1,w movwf xacc2+1 movf xarr+0,w addlw 7 movwf FSR bcf STATUS,IRP btfsc xacc2+1,0 bsf STATUS,IRP movf xacc1,w addwf INDF,w movwf result Regards Sergio Masci -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads