函数不应在块范围内声明

functions shall not be declared at block scope

我无法理解以下 misra 规则,“函数不得在块范围内声明”。文档中给出的解释是 "A function declared at block scope will refer to a member of the enclosing namespace, and so the declaration should be explicitly placed at the namespace level." will refer to member of enclosing namespace 是什么意思?有人可以澄清一下吗?

这意味着当你有这个时,foo 将在 bar 之外,在命名空间中有它的定义:

namespace {
    void bar() {
        void foo();
    }

    //could define foo here
}

意思是将声明移到与定义相同的级别:

namespace {
    void foo();

    void bar() {}

    //could define foo here
}