r/C_Programming • • 2d ago

Tidy translucent typedefs

https://tavianator.com/2026/translucent_2.html

Recently discovered a nice way to get custom warnings with Clang, so I wrote it up.

34 Upvotes

4 comments sorted by

7

u/Accurate_Appeal_3110 2d ago

This is really neat! Could be really useful on enums to prevent implicit conversions to and from its underlying type, like C++'s enum classes

1

u/bacmod 1d ago

Give me a source to run it.

4

u/tavianator 1d ago

You can copy the snippets from the post to try it out, or see https://github.com/tavianator/bfs/commit/d0e87c0f9d3baf4cacd06db6f8f9273866308a52

2

u/tstanisl 1d ago

Interesting.

I've been looking for a way to annotate types with some form of attributes to express additional semantics like "owned", "sized", "stb_vector", etc. And some means of defining rules if the gaining/dropping attribute requires an explicit cast. I hoped to find some popular extensions but I could not find a good one. Using alignment requirements is definitely a bit scary hack but it gets job done for most cases. thank you