Unlike Post-C11 where we sat on our ass and twiddled our thumbs, we do WORK with this brave new WG14. We're already hard at work fixing mistakes from previous standards, this time with _Generic in C2y!

With special thanks to @AaronBallman !

ThePhD | Improving _Generic in C2y | The Pasture | thephd.dev/improving-_generic-

Follow

@thephd This is nice, but my bigger problem with _Generic is that it checks the semantics of non-matched expressions too.
ˋˋˋ
_Generic(x, struct a: x.x, int: x)
ˋˋˋ
This currently fails if x is an int. There are workarounds, but they are really annoying, hard to read and error prone.
ˋˋˋ
_Generic(x, struct a: _Generic(x, struct a: x, default: (struct a){0}).x, int: x)
ˋˋˋ

· · Web · 1 · 0 · 0

@DPA This is intentional and by-design for _Generic, but we do understand that many folk get really pissed off they can't use it as a way of writing more robust generic code. There are a few workarounds but they're mostly unsatisfactory and poor to use, as you've shown here.

We need investment in better. But that is going to require folks to start rolling up their sleeves and putting things out in compilers, to see what they can try to make happen.

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!