I heard C11 added generics. I’ve googled a bit, looked at some articles, understood there’s a new keyword ( _Generic ) and all. But I can’t seem to grasp it all.
Is it something like the generics in C# or templates in C++? Can anyone give me a brief explanation of the C11 definition of generics, its syntax and a simple sample usage example?
This is a pretty good introduction. Here’s the Overview:
Basically it works like a kind of
switch, where the labels are type names which are tested against the type of the first expression (the'a'above). The result becomes the result of evaluating the_Generic().