Monday, April 13, 2015

Static inline functions in embedded C.

To declare and define inline static function:

1) Do not declare it in header file! Any other source files must be unable to know about this function's existence.
2) Instead, declare it in function prototypes section in source file after variables section and before functions section.
Example: static inline void dmx_flush_idx(void);
3) Place definition of a function in the source file where you define all your functions.
Example:
static inline void dmx_flush_idx(void)
{
    g_rx_cnt = 0;
    g_rx_idx = 0;
    g_tx_cnt = 0;
    g_tx_idx = 0;  
}

When static inline function is declared and defined as described, it passes MISRA 2012 checking in PC-Lint and Atmel Studio's Clang-based Naggy isn't naggy about it ;)

No comments:

Post a Comment