Calling a function with internal linkage via pointer from another translation unit
问题 Can we declare a callback function in an anonymous namespace (thus giving it internal linkage), knowing that it will be called from another translation unit (another library even)? Some lib: void register_callback(void (*cb)()) { .. cb(); .. } Main program namespace { int foo_cb() { ... } // internal linkage } int main() { register_callback(foo_cb); } 回答1: TL;DR: yes, it is ok From [basic.link] (emphasis mine): A name is said to have linkage when it might denote the same object, reference,