Tomasz Stanislawski
2023-01-25 12:43:32 UTC
I've noticed that some new C11 projects often use a pattern:
```
#define some_macro(type) _Generic((type){0}, ...)
```
to dispatch expression depending on some type type`.
The `(type){0}` is a compound literal used to create a dummy value of type `type` that is only used to dispatch expressions in generic selection. This approach is cumbersome and difficult to read.
I think that it would be beneficial to allow both values and types be operands of `_Generic` in a similar way as for `sizeof` operator.
This would let simplify the macro to:
```
#define some_macro(type) _Generic(type, ...)
```
It looks like a relatively trivial change to C grammar and wording of the C standard that will not break any existing code. Or am I missing something?
```
#define some_macro(type) _Generic((type){0}, ...)
```
to dispatch expression depending on some type type`.
The `(type){0}` is a compound literal used to create a dummy value of type `type` that is only used to dispatch expressions in generic selection. This approach is cumbersome and difficult to read.
I think that it would be beneficial to allow both values and types be operands of `_Generic` in a similar way as for `sizeof` operator.
This would let simplify the macro to:
```
#define some_macro(type) _Generic(type, ...)
```
It looks like a relatively trivial change to C grammar and wording of the C standard that will not break any existing code. Or am I missing something?