Skip to content

Move more header inclusions outside extern "C"

Simon McVittie requested to merge wip/smcv/no-headers-in-extern-c into master

This starts from !14 (merged) (thanks to @Rhialto) and then adds an additional commit:

  • Move more header inclusions outside extern "C"

    GLib/GObject/GIO, GTK, GMime, Enchant, Zlib and the bundled uulib library are all well-behaved/C++-friendly C libraries that provide extern "C" wrappers in their header files, either directly or via GLib's G_BEGIN_DECLS/G_END_DECLS macros. As a result, there is no need to wrap their header inclusions in a redundant extern "C" block.

    The redundant extern "C" can be harmful in some cases, where an otherwise C-based library detects that its headers are being compiled as C++ via the __cplusplus macro and changes its compile-time behaviour accordingly. In particular, GLib 2.68 uses C++ features to implement the glib_typeof macro where available, so that it can make macros like g_object_ref() more type-safe. This results in GLib headers failing to compile when wrapped in a redundant extern "C" block.

    On glibc-based systems (and probably every other reasonable Unix implementation), the Standard C library headers also do not require wrapping in an extern "C" block, but it might be the case that there are older Unix systems where the extern "C" block is required. I have not moved those header inclusions outside extern "C" in this commit, although perhaps they should be.

    Resolves: #128 (closed)

@Rhialto, you're welcome to incorporate this change into !14 (merged) if you would prefer.

I have successfully compiled Debian's pan 0.146-2 package with the addition of these two commits against GLib 2.68, and confirmed that it resolves the build failure, but I have not otherwise tested the resulting executable (I'm doing QA work for Debian, and I am not a user of pan myself).

To resolve #128 (closed), it's sufficient to apply either this or !16 (merged), but it would be most robust to do both.

Edited by Simon McVittie

Merge request reports