one-definition-rule

Do distinct functions have distinct addresses?

百般思念 提交于 2019-11-26 11:46:13
Consider these two functions: void foo() {} void bar() {} is it guaranteed that &foo != &bar ? Similarly, template<class T> void foo() { } is it guaranteed that &foo<int> != &foo<double> ? There are two linkers I know of that fold function definitions together. MSVC aggressively COMDAT folds functions, so two functions with the same implementation can be turned into one function. As a side effect, the two functions share the same address. I was under the impression that this was illegal, but I cannot find where in the standard it is made illegal. The Gold linker also folds functions, with both

Do distinct functions have distinct addresses?

Deadly 提交于 2019-11-26 02:20:33
问题 Consider these two functions: void foo() {} void bar() {} is it guaranteed that &foo != &bar ? Similarly, template<class T> void foo() { } is it guaranteed that &foo<int> != &foo<double> ? There are two linkers I know of that fold function definitions together. MSVC aggressively COMDAT folds functions, so two functions with the same implementation can be turned into one function. As a side effect, the two functions share the same address. I was under the impression that this was illegal, but

When should I write the keyword &#39;inline&#39; for a function/method?

两盒软妹~` 提交于 2019-11-25 21:45:29
问题 When should I write the keyword inline for a function/method in C++? After seeing some answers, some related questions: When should I not write the keyword \'inline\' for a function/method in C++? When will the compiler not know when to make a function/method \'inline\'? Does it matter if an application is multithreaded when one writes \'inline\' for a function/method? 回答1: Oh man, one of my pet peeves. inline is more like static or extern than a directive telling the compiler to inline your