1

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?

template boy
  • 9,760
  • 4
  • 53
  • 93

1 Answers1

7

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.

Community
  • 1
  • 1
Csq
  • 5,627
  • 6
  • 24
  • 37