Hacker News new | past | comments | ask | show | jobs | submit login

There's also the macro expansion/amplification issue (explained at the end of the page you reference). _Generic seems a dead end, it doesn't even work in practice for <tgmath.h>.



That kind of problem of macro expansion was well explored in a recent Lwn article.. Kilobytes long expansions for some simple operations.

https://lwn.net/SubscriberLink/983965/1240798fdfe236df/

This merits changes in C too but I don't know what if it's not templates.


> This merits changes in C too but I don't know what if it's not templates.

C’s preprocessor is really weak-compared e.g to M4, or the PL/I preprocessor. Yet people manage to do all kinds of amazing tricks with it. The price of those tricks, is a big blowout in preprocessing time. If they added some of the missing features (e.g. conditional macro expansion, iteration), people would be able to achieve the same things with far better performance.

Obviously that couldn’t do everything templates could do - even with a much more powerful macro system, macros would still be ignorant of types - and if they became type-aware, they’d essentially be templates by another name. Still, more powerful macros could deliver a lot of benefits (in compilation time and ease of understanding) for real world code bases, even if C templates never happen.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: