logoalt Hacker News

Parameterized types in C using the new tag compatibility rule

71 pointsby ingvetoday at 5:31 AM19 commentsview on HN

Comments

fuhsnntoday at 9:33 AM

The recent #def #enddef proposal[1] would eliminate the need for backslashes to define readable macros, making this pattern much more pleasant, finger crossed for its inclusion in C2Y!

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3531.txt

show 2 replies
JonChesterfieldtoday at 12:19 PM

Not personally interested in this hack, but https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf means struct foo {} defined multiple times with the same fields in the same TU now refers to the same thing instead of to UB and that is a good bugfix.

unwindtoday at 8:20 AM

I think this is an interesting change, even though I (as someone who has loved C for 30+ years and use it daily in a professional capacity) don't immediately see a lot of use-cases I'm sure they can be found as the author demonstrates. Cool, and a good post!

show 1 reply
rwmjtoday at 9:21 AM

Slighty off-topic, why is he using ptrdiff_t (instead of size_t) for the cap & len types?

show 2 replies
tialaramextoday at 9:37 AM

It seems as though this makes it impossible to do the new-type paradigm in C23 ? If Goose and Beaver differ only in their name, C now thinks they're the same type so too bad we can tell a Beaver to fly even though we deliberately required a Goose ?

show 1 reply
Suractoday at 9:17 AM

i fear this will make slopy code compile more often OK.

show 2 replies