3 ms·
Generics are fine. Its useful to have some introspection into the data that compiler has. Thats the whole point of macros in the first place. The behavior with
by ActorNightly 3y ago
Generics are fine. Its useful to have some introspection into the data that compiler has. Thats the whole point of macros in the first place.
The behavior with _Generic is basically emergent behavior from implementation of macro processors. Macro replacements occur prior to actual compilation, so no compiler context exists for x, as such all code paths must be valid.
Its much easier to require the programmer typecast x in the replacement value then start trying to shoehorn the compiler context into macro processors.
- Dylan16807 3y ago> Macro replacements occur prior to actual compilation, so no compiler context exists for x, as such all code paths must be valid. How is it throwing an error like "invalid type argument of ‘->’" if there's no compiler context? And why does an error like that get in the way of macro replacements? (That might be the wrong message but the article says you at least get an equivalent.)
- ActorNightly 3y agoI mean in the sense of expanding the macro. It doesn't look at the type of operand at the macro expansion step, it simply replaces it with the _Generic() function call, which contains all the expressions, and each expression is parsed, and thus must be valid.
- Dylan16807 3y ago> It doesn't look at the type > each expression is parsed, and thus must be valid. There's multiple kinds of "valid". The code has valid syntax but invalid types. The preprocessor doesn't understand types, so it can't know the code has invalid types, right? So this error is not happening in the preprocessor, right? Therefore changing this behavior would not require preprocessor changes/shoehorning. This error is not a consequence of how the preprocessor works.
- teo_zero 3y ago_Generic is not part of the macro level.