Reputation: 405
I've been reading about inline functions in C++ on Inline Functions in C++.
My questions are:
Upvotes: 0
Views: 220
Reputation: 79
1) Yes as it tells the compiler it can replace the function definitions wherever those are being called.
2) When performance is needed, when the overhead of the function calls is too important compare to the function's job. It is well explained in cplusplus.com :
A normal function call instruction is encountered, the program stores the memory address of the instructions immediately following the function call statement, loads the function being called into the memory, copies argument values, jumps to the memory location of the called function, executes the function codes, stores the return value of the function, and then jumps back to the address of the instruction that was saved just before executing the called function. Too much run time overhead.
3) I can't see any link between inline and ISR functions.
Upvotes: 1
Reputation: 14438
C++ Super FAQ Inline function says that:
inline functions might make it larger: This is the notion of code bloat, as described above. For example, if a system has 100 inline functions each of which expands to 100 bytes of executable code and is called in 100 places, that’s an increase of 1MB. Is that 1MB going to cause problems? Who knows, but it is possible that that last 1MB could cause the system to “thrash,” and that could slow things down.
inline functions might make it smaller: The compiler often generates more code to push/pop registers/parameters than it would by inline-expanding the function’s body. This happens with very small functions, and it also happens with large functions when the optimizer is able to remove a lot of redundant code through procedural integration — that is, when the optimizer is able to make the large function small.
Compilers are so smart so that they automatically perform inlining. inline
is just a hint to the compiler which compiler is not required to obey.
inline
keyword has nothing to do with ISR.
Upvotes: 2