问题
Why does MISRA recommends a inline function to be declared with static storage class? While the keyword inline is a hint to compiler to replace all function calls with actual function body and compiler may or may not perform it, how does giving a internal linkage (static) or external linkage (extern) to a function affect the inline operation by the compiler?
回答1:
MISRA C:2012 gives the rationale for rule 8.10 as:
Rationale
If an inline function is declared with external linkage but not defined in the same translation unit, the behaviour is undefined.
A call to an inline function declared with external linkage may call the external definition of the function, or it may use the inline definition. Although this should not affect the behaviour of the called function, it might affect execution timing and therefore have an impact on a real-time program.
来源:https://stackoverflow.com/questions/51714178/misra-2012-rule-8-10-static-inline