Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

functions shall not be declared at block scope

Tags:

c++

misra

I couldn't able to understand the following misra rule, " functions shall not be declared at block scope " . the explanation given in the document is "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." What they mean by will refer to member of enclosing namespace? Could someone clarify?

like image 224
Kumar Avatar asked May 30 '26 06:05

Kumar


1 Answers

It means that when you have this, foo will have its definition outside of bar, in the namespace:

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

    //could define foo here
}

What it's saying is to just move the declaration out to the same level as the definition:

namespace {
    void foo();

    void bar() {}

    //could define foo here
}
like image 162
chris Avatar answered May 31 '26 20:05

chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!