29-04-2016, 10:43 AM
I have to disagree, 7-3-1 is not the problem here, 16-2-1 is (see http://www.misra.org.uk/forum/viewtopic....1549#p3031)
Typically, in mixed C/C++ applications, you require extern "C" in the C Header only, because the C Module is compiled with a C Compiler and the C++ Module with a C++ Compiler.
If the C Header is checked with MISRA C++ (because the C++ module is), you break 16-2-1 (illustration below).
legacy.h
legacy.c
main.cpp
I think MISRA has not put much thought into mixed C/C++ scenarios.
Typically, in mixed C/C++ applications, you require extern "C" in the C Header only, because the C Module is compiled with a C Compiler and the C++ Module with a C++ Compiler.
If the C Header is checked with MISRA C++ (because the C++ module is), you break 16-2-1 (illustration below).
legacy.h
Code:
#ifndef LEGACY_H
#define LEGACY_H
#ifdef __cplusplus// MISRA C 2012 compliant, but non-compliant with MISRA C++ 16-2-1
extern "C" {// compliant with MISRA C++ 7-3-1
#endif
void foo(void);
#ifdef __cplusplus// MISRA C 2012 compliant, but non-compliant with MISRA C++ 16-2-1
}
#endif
#endif
Code:
#include "legacy.h"
/* no extern "C" required*/
void foo(void)
{
}
Code:
#include "legacy.h"// compliant, no extern "C" required either
int main(void)
{
foo();
return 0;
}
I think MISRA has not put much thought into mixed C/C++ scenarios.
<t></t>