我尝试通过以下实验验证了这一点。代码和输出如下:
[Fooo@EXP]$ cat namespacestd.cpp
#include<iostream>
#ifdef STD
using namespace std;
#endif
int main()
{
#ifndef STD
std::cout<<"\n ==> Workign \n";
#else
cout<<"\n ==> Workign \n";
#endif
return 0;
}
[Fooo@EXP]$ time g++ -c namespacestd.cpp -DSTD
real 0m0.246s
user 0m0.215s
sys 0m0.030s
[Fooo@EXP]$ size namespacestd.o
text data bss dec hex filename
310 8 1 319 13f namespacestd.o
[Fooo@EXP]$ time g++ -c namespacestd.cpp
real 0m0.258s
user 0m0.224s
sys 0m0.034s
[Fooo@EXP]$ size namespacestd.o
text data bss dec hex filename
310 8 1 319 13f namespacestd.o
[Fooo@EXP]$ time g++ -o namespacestd namespacestd.cpp -DSTD
real 0m0.293s
user 0m0.251s
sys 0m0.042s
[Fooo@EXP]$ size namespacestd
text data bss dec hex filename
1980 580 288 2848 b20 namespacestd
[Fooo@EXP]$ time g++ -o namespacestd namespacestd.cpp
real 0m0.274s
user 0m0.239s
sys 0m0.035s
[Fooo@EXP]$ size namespacestd
text data bss dec hex filename
1980 580 288 2848 b20 namespacestd
[Fooo@EXP]$
根据我的实验,我发现
二进制文件的大小没有影响
唯一的区别在于
编译时间有所不同.
如果我的结论有误,请指出
谢谢
using
可能会导致更多的工作),但这只是理论上的问题。 - Matthieu M.g++
将至少编译几十个文件来编译该程序,而时间可能会有所变化。 - Steve Jessop