Why generic in c




















The type after conversion is compared with type-name s from the list of associations. If the type is compatible with the type-name of one of the associations, then the type, value, and value category of the generic selection are the type, value, and value category of the expression that appears after the colon for that type-name. If none of the type-name s are compatible with the type of the controlling-expression , and the default association is provided, then the type, value, and value category of the generic selection are the type, value, and value category of the expression after the default : label.

The controlling-expression and the expression s of the selections that are not chosen are never evaluated.

All value categories , including function designators and void expressions, are allowed as expression s in a generic selection, and if selected, the generic selection itself has the same value category.

Generic selections, introduced in C11, gave the programmers the ability to write similar type-dependent code. The following behavior-changing defect reports were applied retroactively to previously published C standards. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments.

What's New. We use cookies to ensure you have the best browsing experience on our website. Improve this question. There are some interesting answers : — Jehan. Add a comment. Active Oldest Votes. Improve this answer. Groshh 1 1 silver badge 10 10 bronze badges.

Paul R Paul R k 33 33 gold badges silver badges bronze badges. Jonathan Leffler k gold badges silver badges bronze badges.

Jehan Jehan 5 5 silver badges 13 13 bronze badges. I like the style of the final call, but I was trying to archive this without large macros. That's what I liked about PaulR's answer: The macro was pretty short, and was reusable at other places : — fb I've updated my answer now to show how to generate multiple functions for all the required types in one translation unit. Show 2 more comments. Sign up or log in Sign up using Google. Sign up using Facebook.



0コメント

  • 1000 / 1000