What is this for in a header file?

I have seen this in a few places but don’t know what is its purpose.

#ifdef __cplusplus
extern "C"
{
#endif
...
#ifdef __cplusplus
}

I must admit, my text on C++ is copyright 1993.

C++ does name mangling. The C++ name for a function like void OutputReport(void) is _Z12OutputReportv.

C puts an underline in front of names but otherwise does not modify them. The C name for a function like void OutputReport(void) is _OutputReport.

When C and C++ code is combined, the least common denominator must be used: C naming. extern "C" {} tells the C++ compiler not to perform name mangling on anything inside the braces. The __cplusplus is only defined for the C++ compiler. So...

#ifdef __cplusplus
// This is included for the C++ compiler but not the C compiler
extern "C"
{
  // Everything between here...
#endif

...

#ifdef __cplusplus
  // ...and here is defined with name mangling inhibited.
}
#endif

Thanks for the informative reply.

I have a lot of learning to do about this environment. Since I haven't been able to find a comprehensive manual on the Arduino IDE I am relying on search engines and this forum which has proved to be most helpful.