I am writing a header-only library, and I can’t make up my mind between declaring the functions I provide to the user static or inline. Is there any reason why I should prefer one to the other in that case?
I am writing a header-only library, and I can’t make up my mind between
Share
They both provide different functionalities.
There are two implications of using the
inlinekeyword(§ 7.1.3/4):The
statickeyword on the function forces theinlinefunction to have an internal linkage(inline functions have external linkage) Each instance of such a function is treated as a separate function(address of each function is different) and each instance of these functions have their own copies of static local variables & string literals(an inline function has only one copy of these)