似乎全局上下文中的所有函数和名称空间都是由预处理器和汇编器整体传输的,这是有道理的。
但是我只是想知道在链接步骤中是否有一种方法可以缩小那些。
例如
编译此文件:
void A_function_in_the_global_context() {}
unsigned int A_variable_in_the_global_context = 10;
namespace A_namespace_in_the_global_context {
void A_function_inside_a_namespace_in_the_global_context () {
}
}
int main () {
return 0;
}
通过:
clang++ \
-std=c++2a \
-stdlib=libc++ \
-rtlib=compiler-rt \
-O3 \
Start.cpp \
-o Start;
产生一个输出,所有名称完整无缺(如utf8)。有没有办法以某种方式将其最小化?
看起来像匿名名称空间或static关键字将完全做到这一点。
static unsigned int A_static_variable_in_the_global_context = 11;
static void A_static_function_in_the_global_context () {}
namespace {
#include <stdio.h>
void A_function_in_the_global_context() {}
unsigned int A_variable_in_the_global_context = 10;
namespace A_namespace_in_the_global_context {
void A_function_inside_a_namespace_in_the_global_context () {
printf("ok?");
}
}
}
int main () {
A_function_in_the_global_context();
A_namespace_in_the_global_context::A_function_inside_a_namespace_in_the_global_context();
return 0;
}
但是,我在输出中发现“ printf” ...