在这种情况下
namespace n { void f() { void another_function(); } }
应该在命名空间n或外部定义函数another_function吗? VS 2012(与November CTP一起)说它应该在外面,Mac上的GCC 4.7.2说应该在里面.如果我做错了,我会从链接器中得到未定义的符号错误.
我一般都相信GCC更符合标准,但这是C,你永远不能确定.
解决方法
C 11 3.5(以及C 03)
7 When a block scope declaration of an entity with linkage is not found
to refer to some other declaration,then that entity is a member of
the innermost enclosing namespace. However such a declaration does not
introduce the member name in its namespace scope.
示例中的声明声明了n :: another_function.