Skip to content

Add C++ support#94

Merged
eteran merged 2 commits into
eteran:masterfrom
nakidai:master
Jun 12, 2026
Merged

Add C++ support#94
eteran merged 2 commits into
eteran:masterfrom
nakidai:master

Conversation

@nakidai

@nakidai nakidai commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I've seen that #70 had some discussion recently and this is my solution. clang++ compiles test.c as well as example.c successfully. unit-tests.c fails to compile but because of itself, not the library, and since this is a C library I don't see reasons to run tests with a C++ compiler and therefore didn't touch the file.

To be portable across C and C++ cvector needs only a couple of changes where C++ needs explicit casts. A macro cvector_typeof is made to cast in C++ and do nothing in C and it is applied in needed places

To be portable across C and C++ cvector needs only a couple of changes
where C++ needs explicit casts. A macro cvector_typeof is made to cast
in C++ and do nothing in C and it is applied in needed places
@eteran

eteran commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Oh geez, I was very much over thinking this! You're right that we can just use macros to do different work in C++ than C!

I do think that maybe we can get away with not needing type traits though!

I bet we can use C++ type of on vec[0] and cast to a pointer to that type.

Might be better?

std::remove_reference can be replaced with just taking an address of
the first element
@nakidai

nakidai commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Yes you're right there, I was thinking of removing reference on the surface and this can indeed be done easier

@eteran

eteran commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Nice, I'll want to double check but conceptually this looks good to me.

@eteran eteran merged commit 12eddc4 into eteran:master Jun 12, 2026
5 checks passed
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