Build-C-as-C++ Patches#849
Open
AE1020 wants to merge 3 commits into
Open
Conversation
There is already a uint32_max defined in the file globally as a shorthand for the constant from std::numeric_limits.
It's defined in the same file. This is a similar solution to PR 326 RoaringBitmap#326 (comment)
AE1020
force-pushed
the
simple-cplusplus-patches
branch
from
July 17, 2026 00:59
dc78340 to
2575e12
Compare
The bitset_t was once an internal implementation detail, but was made a part of the api. The roaring::internal namespace was still being used on bitset_t. This moves it to the API namespace. Also, the `misc` namespace where the configreport put its routines was not being included in some places. This fixes that. Finally, the various containers were being exposed as api vs. internal. While things like the iterators are api, things like run_container_t should be internal.
AE1020
force-pushed
the
simple-cplusplus-patches
branch
from
July 17, 2026 11:28
2575e12 to
f8ef82b
Compare
AE1020
commented
Jul 17, 2026
| #include "test.h" | ||
|
|
||
| #ifdef __cplusplus // stronger type checking errors if C built in C++ mode | ||
| using namespace roaring::api; |
Contributor
Author
There was a problem hiding this comment.
Upon review I notice this line is actually superfluous: including roaring.h (as opposed to roaring.hh) when building as __cplusplus) automatically includes the roaring::api namespace.
https://github.com/RoaringBitmap/CRoaring/blob/master/include/roaring/roaring.h#L1367-L1382
Perhaps that points to a potential separation of configreport.h vs. configreport.hh that does a similar trick; you don't need a using namespace roaring::misc; if you use the .h version?
| extern "C" { | ||
| namespace roaring { | ||
| namespace internal { | ||
| namespace api { // bitset_t was once internal, but made public in the API |
Contributor
There was a problem hiding this comment.
I don't think this comment belongs in the code. That's information for the Git commit message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As per C++ core guidelines CPL.2, it's best for C code to be buildable with a C++ compiler. (my codebase using CRoaring has to build as both C99+ and C++11+). Because of this I had contributed some of the necessary changes to CRoaring to achieve that some years ago.
At that time, I also slipped in some "experimental" ideas involving how
container_t*could be avoid*in C, but in C++ it could use the "empty base class optimization" with the container subclasses inheriting from it. This meant it would be type checked more strongly if built as C++...so that you got the benefit of typed inheritance...only allowing containers to be passed tocontainer_t*vs arbitrary pointers.It was the start of a good idea, but only the start (and the way I did it then was often more clutter than it provided benefit, as well as an ABI break with C-built code in some compilers in some circumstances). Those ideas have evolved into a vastly richer framework now... which may be applied to many problems. Including solving your memory allocation failures/propagation in a "Rust-like" way, by using the type system to annotate the return values of routines that can fail, and forcing compile-time errors when triage is not performed:
https://needful.metaeducation.com/
This new model removes the wacky C++ from CRoaring's codebase entirely; the "enhancements" are in a repository that only those who wish to build with instrumentation "install". It becomes a tool that you sideload in certain developer/CI builds--not part of CRoaring itself. (Your focus on "amalgamation" demonstrates you are interested in pragmatic packaging, and Needful is also very pragmatic: removing the clutter, while delivering the benefit.)
Which is good: e.g. in my fork I've eliminated of all the below kind of junk, while delivering the actual value that a "C++ enhanced build" was theoretically supposed to provide:
CRoaring/include/roaring/containers/container_defs.h
Lines 73 to 88 in d60ba3f
CRoaring/include/roaring/containers/array.h
Lines 54 to 56 in d60ba3f
(etc.) This is all gone, replaced by a (via a single
downcastoperator), that's just#define downcast (void*)in the baseline C distribution (and minor magic in non-enhanced C++ builds)... but metaprogramming sorcery once you sideload the C++ enhanced files. It detects the target type implicitly without you having to say what it is and validates the inheritance relationship, it won't downcast const pointers to non-const, it won't cast double-pointers to single ones, it can compile-time restrict the allowed to and from casts, or runtime validate the bit patterns based on what you're casting to what, and so on and so forth...But to get the ball rolling to show you what I mean, the atrophy in C++ builds has to be fixed first. Here are some (I hope) uncontroversial patches to start with.