IssueRaiser

#define add(a, b) _Generic(a, int: addi, char*: adds)(a, b) Just because you can doesn't mean you should.

#define add(a, b) _Generic(a, int: addi, char*: adds)(a, b) Just because you can doesn't mean you should. Someday, someone will have to read that code. Note that when "add" returns a string, it's done an allocation, but for the integer case, it hasn't called "malloc". Now you'll now need to know the type to get rid of it. Back in C99, generic trig functions were put in to make the number-crunching people happy. After all, FORTRAN has them. Everybody was tired of different versions of math libraries for "float" and "double". Then in C11, the mechanism behind that, "_Generic", was exposed. Now, anybody can use it. But, probably, they shouldn't. [1] [1] http://www.robertgamble.net/2012/01/c11-generic-selections.h...

Posted by Animats on Jul 26, 2015, 6:25 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments

hackernews (Other)

#define add(a, b) _Generic(a, int: addi, char*: adds)(a, b) Just because you can doesn't mean you should.

AnimatsJul 26, 2015, 6:25 PM

#define add(a, b) _Generic(a, int: addi, char*: adds)(a, b) Just because you can doesn't mean you should. Someday, someone will have to read that code. Note that when "add" returns a string, it's done an allocation, but for the integer case, it hasn't called "malloc". Now you'll now need to know the type to get rid of it. Back in C99, generic trig functions were put in to make the number-crunching people happy. After all, FORTRAN has them. Everybody was tired of different versions of math libraries for "float" and "double". Then in C11, the mechanism behind that, "_Generic", was exposed. Now, anybody can use it. But, probably, they shouldn't. [1] [1] http://www.robertgamble.net/2012/01/c11-generic-selections.h...

Comments (0)

No comments yet. Start the discussion.

Comment on this issue