Skip to content

Replace _Bool with bool in C interface headers for C++ compatibility#42

Open
luca-heltai wants to merge 1 commit into
sfilippone:developmentfrom
luca-heltai:fix-bool-cpp-compatibility
Open

Replace _Bool with bool in C interface headers for C++ compatibility#42
luca-heltai wants to merge 1 commit into
sfilippone:developmentfrom
luca-heltai:fix-bool-cpp-compatibility

Conversation

@luca-heltai

Copy link
Copy Markdown

Problem

The C interface headers psb_c_dbase.h, psb_c_sbase.h, psb_c_cbase.h, and psb_c_zbase.h use _Bool (a C11 keyword) in the *sprn function declarations.

When these headers are included from C++ code (via extern "C"), the C++ compiler fails with:

error: unknown type name "__Bool"

This is a known portability issue — _Bool is C-only and not recognized by C++ compilers, even though the headers are designed to be included from both C and C++ (they already use #ifdef __cplusplus / extern "C" {).

Fix

Replace _Bool with bool (from <stdbool.h>), which is already included via psb_c_base.h. This type works correctly in both C (where bool is a typedef for _Bool) and C++ (where bool is a native type).

Files changed

  • cbind/base/psb_c_dbase.hpsb_c_dsprn()
  • cbind/base/psb_c_sbase.hpsb_c_ssprn()
  • cbind/base/psb_c_cbase.hpsb_c_csprn()
  • cbind/base/psb_c_zbase.hpsb_c_zsprn()

This change has no effect on the ABI since bool and _Bool are both mapped to int in the C/ABI calling convention (via Fortran bind(c) with logical).

_Bool is a C11 keyword that is not recognized by C++ compilers,
causing build failures when PSBLAS headers are included from C++.
The headers already include <stdbool.h> (via psb_c_base.h) which
defines bool as a portable alias, so use bool instead of _Bool.

This fixes errors like:
  error: unknown type name '_Bool'
in psb_c_dsprn(), psb_c_ssprn(), psb_c_csprn(), psb_c_zsprn().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant