I have read somewhere that for functions not returning values, if a return statement exists inline expansion may not work.
Can anybody tell me the exact reason for this?
I have read somewhere that for functions not returning values, if a return statement exists inline expansion may not work.
Can anybody tell me the exact reason for this?
The inline
keyword is more of a hint to the compiler than an explicit directive these days. There is no specific rule about not inlining functions with return statements. This would be pointless anyway because that is the only main difference between macros and inline functions.
Different compilers will generate different code for inline functions with just the inline
keyword. MSC compiler has a __forceinline
keyword which will force a function to be inline. Note that indiscriminate inlining will generate more code. These days performance overheads are rarely because of the overhead of a function jump. I would advise you to profile your code and not do any premature optimizations.
There is no such rule. However, inline is a request to the compiler to make this as macro if possible, for complex functions, inlining will be ignored and will be just like normal function.