3 ms·
I haven't seen a major project written in C that _didn't_ use some magical macro-foo. PostgreSQL source code for example, has a foreach() macro that loops thru
by murftown 9y ago
I haven't seen a major project written in C that _didn't_ use some magical macro-foo.
PostgreSQL source code for example, has a foreach() macro that loops thru a linked list.
- varjag 9y agoThere are straightforward macro things like comparisons, list/queue head declarations and perhaps iterators (tacky IMO) that are understood by most practising C programmers. Deviate from that too much, you effectively penalize collaborators/future maintainers by forcing to learn your toy language. At the same time the abstractions provided by C preprocessor are too weak for significant productivity gain via elaborate DSL route. It's better to rather stick to universally understood vocabulary than force your sometimes buggy, often inflexible language upon others.
- murftown 9y agoI agree that there's a risk of getting off into the weeds. That being said, C Preprocessor behavior is pretty simple once you know it, and modern compilers are pretty good these days about helping you see what happens when you have an error in your macro-expanded code. You're right though, good to stick to the universally understood vocabulary.