AnsweredAssumed Answered

Unterminated extern "C" bracketing

Question asked by John Strohm on Apr 10, 2015
Latest reply on Apr 13, 2015 by Kan_Li

When declaring things in a header file that must be visible/linkable from both C and C++, the standard technique is:

 

#ifdef __cplusplus

extern "C" {

#endif

    /* declarations go here */

#ifdef __cplusplus

}

#endif

 

One occasionally sees an alternate form:

 

#if defined(__cplusplus)

extern "C" {

#endif

    /* declarations go here */

#if defined(__cplusplus)

}

#endif

 

In the USB 5.0 stack, files fsl_usb_ehci_hal.h and fsl_usb_khci_hal.h contain the first (opening) block but never the second (closing) block.  File fsl_usb_khci_hal.h contains it in two places.  If those header files are ever imported by a C++ module, the compiler will be very unhappy.

 

Admittedly, these two headers will probably not see C++ usage any time soon.

Outcomes