r/cpp • u/FlyingRhenquest • Oct 24 '26
Fun With C++26 Reflection - Building a Library for Old-Timey C
https://github.com/FlyingRhenquest/fun_with_reflection
35
Upvotes
r/cpp • u/FlyingRhenquest • Oct 24 '26
8
u/FlyingRhenquest Oct 24 '26
I had this idea the other day. Pretty much the entire time I was writing it I was thinking "Yeah, there's no way this could actually work... could it?" Turns out, it can. And it was really pretty simple.
So you can use reflection to build structures for C using templates and reflection features, so long as you can provide C a header file that it understands. This takes you through building a class that can generate serialization functions for C to use for arbitrary C structures and output a header for the library with C++26 reflection.