I have been reading about declaring anonymous namespaces for achieving a lower linking-time.
However, I have read that declaring anonymous namespaces in header files are trully not recommended:
When an unnamed namespace is defined in a header file, it can lead to surprising results. Due to default internal linkage, each translation unit will define its own unique instance of members of the unnamed namespace that are ODR-used within that translation unit. This can cause unexpected results, bloat the resulting executable, or inadvertently trigger undefined behavior due to one-definition rule (ODR) violations.
The above is a quote extracted from the link below, in which there are several examples of anonymous namespaces' unexpected behaviors: https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL59-CPP.+Do+not+define+an+unnamed+namespace+in+a+header+file
So, my questions are:
The mentioned problems only applies to anonymous-namespace variables, not methods. Is that right?
Does the same problem appears when using static keyword for forcing internal linkage with variables? If so, is there any other way to achive this in a safety way?