4 ms·
Speaking of the C preprocessor, I found this recently: from the Firefox source code, a red-black tree written entirely in 800 lines of C macros: http://searchfo
by kibwen 9y ago
Speaking of the C preprocessor, I found this recently: from the Firefox source code, a red-black tree written entirely in 800 lines of C macros: http://searchfox.org/mozilla-central/rev/f54c1723befe6bcc7229f005217d5c681128fcad/memory/build/rb.h http://searchfox.org/mozilla-central/rev/f54c1723befe6bcc722... . Submitted for your enjoyment. :)
- jstewartmobile 9y agoI've used OpenBSD's version of that more times than I care to remember: http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/sys/tree.h?rev=1.29 http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/...
- nikbackm 9y agoLooks to be some small amount of C code in those macros as well.
- throwme211345 9y agoWhy would someone do that?
- dboreham 9y agoBecause long ago (and probably in a different product) making a function call was significantly costly and worthwhile optimizing away via macros.
- jstewartmobile 9y agoThat is how we do "generics" in C. Not happy about it, just sayin'.
- naasking 9y agoThere are whole libraries that provide these sorts of generic containers for C: http://sglib.sourceforge.net/ http://sglib.sourceforge.net/ http://klib.sourceforge.net/ http://klib.sourceforge.net/ https://github.com/pmj/genccont https://github.com/pmj/genccont