Skip to content

Make public headers C++-compatible #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged

Conversation

glebm
Copy link
Contributor

@glebm glebm commented Feb 2, 2025

Allow #include <SheenBidi.h> in C++ without having to wrap it in extern "C".

@glebm glebm force-pushed the cpp-guards branch 2 times, most recently from 00bf56d to 4d47197 Compare February 5, 2025 22:19
@glebm
Copy link
Contributor Author

glebm commented Feb 7, 2025

@mta452 Could you please take a look at this and my other 2 PRs? They make it easier to use SheenBidi in C++.

@mta452
Copy link
Member

mta452 commented Feb 8, 2025

This was raised previously in issue #7 as well. However, I intentionally want to avoid adding support for other languages in the main library itself to keep things simple. I feel it makes more sense to handle such cases in the target language.

@mta452
Copy link
Member

mta452 commented Feb 8, 2025

Can you please discuss the ideas in a ticket before actually starting the implementation? It would be beneficial to discuss the pros and cons beforehand.

@glebm
Copy link
Contributor Author

glebm commented Feb 8, 2025

I feel it makes more sense to handle such cases in the target language.

C and C++ are different languages but are part of the same ecosystem.
As this is the only thing needed to achieve C++ compatibility, C libraries generally do this.

For example: all GNU libraries (e.g. gettext), SDL, Linux support libraries (e.g. liburing), etc.

This makes it easier for C++ users and does not have any maintenance overhead. On the other hand, as this library becomes more popular (and I believe it will), some maintenance effort will be spent replying to issues that people open about this.

This is not a major issue of course but it'd be nice to not have to explain to C++ developers (who may not even be familiar with extern) that SheenBidi needs special handling.

Can you please discuss the ideas in a ticket before actually starting the implementation? It would be beneficial to discuss the pros and cons beforehand.

Sure, for the future PRs. Though often having the code makes the discussion easier and makes the effort needed for the implementation clearer.

@mta452
Copy link
Member

mta452 commented Apr 26, 2025

I'm open to adding support for extern "C" in public headers. But it cannot be just plain blocks of #ifdef ... #endif. Maybe putting them in reusable macros would be a better idea.

@glebm
Copy link
Contributor Author

glebm commented Apr 27, 2025

The plain ifdef blocks are what's usually used.

We could define something like this in SBBase.h instead:

#ifdef __cplusplus
#define SB_EXTERN_C_BEGIN extern "C" {
#define SB_EXTERN_C_END }
#else
#define SB_EXTERN_C_BEGIN
#define SB_EXTERN_C_END
#endif

I don't think it's necessarily worth it but if you prefer it I can update this PR to use these macros

glebm added 2 commits April 27, 2025 07:33
Allow `#include <SheenBidi.h>` in C++ without having
to wrap it in `extern "C"`.
@glebm glebm changed the base branch from master to develop April 27, 2025 06:34
@glebm
Copy link
Contributor Author

glebm commented Apr 27, 2025

Changed to macros and retargeted to develop

Copy link
Member

@mta452 mta452 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me 👍

@mta452 mta452 merged commit 69b283b into Tehreer:develop Apr 28, 2025
13 checks passed
@glebm glebm deleted the cpp-guards branch April 28, 2025 16:25
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.

2 participants