看这个简单的程序
#include <cstdio>
#include <cstdlib>
void foo(){ printf("%d",1); }
int main(){ foo(); }
我在 linux 上用 gcc 4.6.4 -std=c++0x -O2 -g -Wall 编译它。和二进制文件 11`238 字节。
但是这段代码产生了 11`150 个字节:
#include <cstdio>
#include <cstdlib>
template< bool = false> void foo(){ printf("%d",1); }
int main(){ foo(); }
我还用 clang 3.3 进行了测试,结果分别为 5684 字节和 5636 字节。
为什么没有模板版本功能产生更多的二进制代码?