请考虑以下代码:
example% cat Example.cc
template <class T> struct S {
void imf() {}
static void smf() {}
};
template class S <int>;
int main() {
}
example%
|
指定了 -template=geninlinefuncs 时,即使在程序中没有调用 S 的两个成员函数,也会在目标文件中生成它们。
example% CC -c -template=geninlinefuncs Example.cc
example% nm -C Example.o
Example.o:
[Index] Value Size Type Bind Other Shndx Name
[5] 0 0 NOTY GLOB 0 ABS __fsr_init_value
[1] 0 0 FILE LOCL 0 ABS b.c
[4] 16 32 FUNC GLOB 0 2 main
[3] 104 24 FUNC LOCL 0 2 void S<int>::imf()
[__1cBS4Ci_Dimf6M_v_]
[2] 64 20 FUNC LOCL 0 2 void S<int>::smf()
[__1cBS4Ci_Dsmf6F_v_]
|