ThePhD

Living disaster, ready to strike!

✨ Somehow Is A C Expert ✨ Smooches Unicode-kun 💕 Pixel Art is Cool 🎨 Banner by Bugurri and Avatar by KIING KIISMET

You must log in to comment.

in reply to @ThePhD's post:

this is nice! i was just thinking about this in terms of an "exactly this type" assertion

sometimes though i've wished _Generic could go in the other direction and admit more conversions, like to be able to have one rule that matches all data pointers or all integer types, particularly for printing sorts of macros like

_Generic((x),
  // handle all types that can convert to `void*`
  const void *: "%p",
  // all types that promote to `int`
  int: "%d",
  ...)

out of curiosity, are there folks that have looked into introducing more "generic" _Generic selectors like that into C?

There is a lot of work that's going into figuring out what more can be done with _Generic. Some people want certain branches to not be evaluated. Others want VLAs to have syntax so they can be matched on. And then, of course, there's the things you want to try to do with better conversions.

I would say if you want to accelerate seeing something you like, you should give a shot at prototyping it in Clang and throwing some code at it to see how it feels. I personally think different variations of _Generic that use a different keyword, e.g. _GenericPromoted (which would do the conversions you speak of known as "default argument promotions").