Rule 6.0.3 has the title
However, with the current MISRA C++:2023 version the amplification does not contain details about the extern "C" declarations and there are no examples that use an extern "C" block.
My question first question: is it OK to use typdefs in extern "C" blocks and also in the global namespace to be able to share these typdefs between C and C++ code?
Example:
Second question: As the rule explicitly mentions extern "C" declarations - what else is allowed or not allowed? (What about, e.g., struct definitions or function definitions?)
Quote:The only declarations in the global namespace should be main, namespace declarations and extern "C" declarations
However, with the current MISRA C++:2023 version the amplification does not contain details about the extern "C" declarations and there are no examples that use an extern "C" block.
My question first question: is it OK to use typdefs in extern "C" blocks and also in the global namespace to be able to share these typdefs between C and C++ code?
Example:
Code:
#ifdef __cplusplus
#include <cstdint>
#else
#include <stdint.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t AddressType_t; /* Compliant? (to be able to share typdefs in C and C++ code this is OK) */
void foo(); /* Compliant? ('foo' needs C linkage and it is OK to have a C function in the global namespace) */
#ifdef __cplusplus
}
#endifSecond question: As the rule explicitly mentions extern "C" declarations - what else is allowed or not allowed? (What about, e.g., struct definitions or function definitions?)

