Difference between revisions of "BoostC Inline Functions"

From OpenCircuits
Jump to navigation Jump to search
(New page: Inline functions are statements that look like functions but do not really call anyting or return, the code is generated right "inline" with the statements before and after the "function c...)
 
Line 3: Line 3:
 
== Ways ==
 
== Ways ==
  
Using a #DEFINE
+
*Using a #DEFINE
Using a inline qualifier in the function definition.
+
*Using a inline qualifier in the function definition.
 
 
  
 
== Reasons ==
 
== Reasons ==

Revision as of 09:41, 7 March 2009

Inline functions are statements that look like functions but do not really call anyting or return, the code is generated right "inline" with the statements before and after the "function call". There are a couple of different ways to do this, and a couple of different reasons to do it.

Ways

  • Using a #DEFINE
  • Using a inline qualifier in the function definition.

Reasons

  • Smaller faster code -- sometimes, sometimes not.
  • Avoiding too deep a call return stack.

Since there is no call/return the stack usage is zip.

  • Make changes to code easier.

If the code would normally have to be changed in many places, changing the definition of the "function" can allow all the changes to be made in one place.

  • Make code more readable.

If a subroutine is called only in one place, it may still make the code more readable by using an inline function to hide or "chunk" low level details.

  • Remove the chance of calling a function from both the main line and the interrupt

Because there are actually two different versions of the function.


#DEFINE Details