C doesn't have (to the best of my knowledge) overloading or templates, right? So how can a set of type-agnostic functions with the same name exist in plain ol' C? The usual compile-time trickery would involve a whole bunch of macros, wouldn't it?
Asked
Active
Viewed 3,458 times
9
-
4Why not just [read it](http://www.google.com/codesearch/p?hl=en#5ge3gHPB4K4/gnu/glibc/glibc-2.1.1.tar.gz|bZFm81g2I8w/glibc-2.1.1/math/tgmath.h)? – Michael Mrozek Apr 28 '10 at 04:03
-
6Michael Mrozek, because it is not available anymore. – Lavir the Whiolet Apr 26 '12 at 09:53
1 Answers
10
There's a great explanation of how it works in GCC here.
Also, if anyone can solve the medium-difficulty exercise, I'd love to know the answer.
-
That was a great read. It makes sense that the whole thing is so kludgy, though a part of me was hoping for a magical "C with Templates" C99. – sync Apr 28 '10 at 04:41
-
+1. Great article. I'd love to hear the solution to the medium-difficulty exercise, too. – mbauman Apr 28 '10 at 05:37
-
4Spoiler for medium-difficulty exercise: Because it would produce the wrong answer for _Bool. – John Marshall Apr 28 '10 at 06:57