I am very surprised that you didn't know that we can use static to change the linkage. You can also use it with variables and get a static bool in a *.cpp file :D
Somehow I never noticed it. Even in this case, it was only about hiding the existance of a helper method which I don't think was the best idea as it introduces positional coupling (does that exist?)...
Someone suggested to use anonymous namespaces instead as in addition "anonymous namespaces allow you to have internal type declarations, something that cannot be achieved through the static."
Anonymous namespaces indeed have the same purpose. After may years, I still prefer static: when you see a function prototype, you immediately know that it has internal linkage. With anonymous namespaces, you have to scroll up the file to see that (or your IDE's hints, if available) to check.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I am very surprised that you didn't know that we can use
static
to change the linkage. You can also use it with variables and get astatic bool
in a *.cpp file :DSomehow I never noticed it. Even in this case, it was only about hiding the existance of a helper method which I don't think was the best idea as it introduces positional coupling (does that exist?)...
Someone suggested to use anonymous namespaces instead as in addition "anonymous namespaces allow you to have internal type declarations, something that cannot be achieved through the static."
Anonymous namespaces indeed have the same purpose. After may years, I still prefer
static
: when you see a function prototype, you immediately know that it has internal linkage. With anonymous namespaces, you have to scroll up the file to see that (or your IDE's hints, if available) to check.