Skip to content

Remove extern "C" { ... } in C files #110079

Closed
@vstinner

Description

@vstinner

Bug report

Until Python 3.11, it was possible to build Python with a C++ compiler: ./configure --with-cxx-main. This build mode has been removed in Python 3.12: in gh-93744 by commit 398ed84:

commit 398ed84dc40abc58e16f5014d44c08f20cb4b5f6
Author: Victor Stinner <[email protected]>
Date:   Fri Aug 5 13:26:58 2022 +0200

    gh-93744: Remove configure --with-cxx-main option (#95651)
    
    Remove the "configure --with-cxx-main" build option: it didn't work
    for many years. Remove the MAINCC variable from configure and
    Makefile.
    
    The MAINCC variable was added by the issue gh-42471: commit
    0f48d98b740110a672b62d467af192ec160e56ba. Previously, --with-cxx-main
    was named --with-cxx.
    
    Keep CXX and LDCXXSHARED variables, even if they are no longer used
    by Python build system.

In the C code, there are still a bunch of extern "C" { ... }:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

This code path is only taken in the C file is built by a C++ compiler which is no longer possible. I simply propose to remove it.


Obviously, the in Python C API, we must keep extern { ... }, since it's required to handle properly C++ name mangling when exposing a C API. The Python C API is now tested by a C++ compiler in test_cpp. This issue is only about C files, not about header (.h) files.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions