7-3-1 declarations and definitions

Moderators: david ward, misra cpp

Post Reply
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

7-3-1 declarations and definitions

Post by gs » Mon Aug 25, 2014 5:33 pm

Does rule 7-3-1 require a function declared at global scope be declared as "extern 'C'" for both the function's declaration and its definition or does one "extern 'C'" for that function suffice? For example, is this okay:

Code: Select all

extern "C" void f();
void f() {}

misra cpp
Posts: 161
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: 7-3-1 declarations and definitions

Post by misra cpp » Tue Oct 11, 2016 10:56 am

What you're written is compliant, but not what the rule intended. The intent of the rule was that no functions would be declared at global scope, other than main or those imported from C libraries using extern "C"
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.7 Declarations (C++)”