4 ms·
For my money, something that looks like a C API with very obviously impossible things going on (passing "naked" names of primitive types like int and float) mak
by unwind 15y ago
For my money, something that looks like a C API with very obviously impossible things going on (passing "naked" names of primitive types like int and float) makes my personal WTF-o-meter go to eleven immediately.
I (of course) had to start reading the code to figure out what was going on, and saw that what looks like a function call is in fact a macro. That explains the "how" but (again, for me) it really doesn't come close to making it feel natural.
C code should look like C code, and you can't write a function that takes a bare "int" as an argument.
- rollypolly 15y agoReminds me of boost.python, which is also macro-heavy.
- orangeduck 15y agoFair enough, I agree that it isn't the prettiest or most natural of code but it isn't any "magic" too far beyond convention. Without C++ templates this is the only way to achieve certain things - and is fairly standardized. See va_args for an example of naked types being passed in the standard library. Really it is not much different from the fact you have to pass a format string to printf.
- unwind 15y agoThat's true, I had forgotten about va_arg()'s use of naked types. I do think the standard library has a bit more license to do weird stuff, and it's fairly well-known that va_* can be macros.