I have a .cpp file which has some static free functions. I know how that would help in a header file, but since the cpp is not included anywhere, what’s the point? Are there any advantages to it?
I have a .cpp file which has some static free functions. I know how
Share
Declaring free functions as
staticgives them internal linkage, which allows the compiler more aggressive optimizations, as it is now guaranteed that nobody outside the TU can see that function. For example, the function might disappear entirely from the assembly and get inlined everywhere, as there is no need to provide a linkable version.Note of course that this also changes the semantics slightly, since you are allowed to have different static functions of the same name in different TUs, while having multiple definitions of non-static functions is an error.