> Everything we've seen here is still normal C, but often we want to associate a function with a type. For instance, the area function we have shown above only works with rectangles, but what if we had circles as well? We'd end up with two functions, one called area_rectangle and one called area_circle.
This is not to call the article into question but only to show that C11 does support generics, allowing for:
You haven't demonstrated the capability of Generics though (which C doesn't really have, only a minimal version). For this particular example, C++ does function overloading on parameters which C cannot hence you need this silly Generic macro hack, it is not clear how much of a win it is. Reminds of the saying that C is the most dynamic programming language since it has void*
It is much cleaner in C++ where you don't need to declare two separate functions names like you did.
This is not to call the article into question but only to show that C11 does support generics, allowing for:
Full code here:https://gist.github.com/williamcotton/a8f429e891cbba5abfadcc...