Reputation: 10480
I have a TU whose global functions won't be used by any other TUs. I read that declaring them as static
gives them internal linkage, and this is good from an optimization standpoint. But I want to know what are the correct situations in which I should use them. Should I always give global functions/variables internal linkage when I know they won't be used anywhere else in the program?
Upvotes: 1
Views: 128
Reputation: 5855
Put them in an unnamed namespace instead.
This is the idiomatic solution in C++ for functions that will be used only in the current TU.
Upvotes: 7