4 ms·
Interesting as highlights of what C preprocessor and compiler extensions can do. But I'd hate seeing it in actual production code.
by varjag 9y ago
Interesting as highlights of what C preprocessor and compiler extensions can do. But I'd hate seeing it in actual production code.
- WalterBright 9y agoI used to be enamored with what I could do with the preprocessor back in the 80's. I've since reverted all of that (in C code I still use) back to mundane uses of the preprocessor. Eventually one tires of no support in the symbolic debugger, program analysis tools, compiler error messages that are based on the post-expansion code, nobody else understands the code, hygiene problems, etc.
- varjag 9y agoExactly my sentiment, especially the collaboration part. If you take it too far, you effectively invent a new language. Forcing it upon others is more about hubris than skills.
- MaxBarraclough 9y ago> you effectively invent a new language Perfect. Can't tell if that's deliberate.
- cryptonector 9y agoDo you use PuTTY? Because PuTTY does crazy C macro things. Actually, maybe not that crazy. It just has C functions that a thousands of lines long, using macros to turn them into fancy Duff's device co-routines.
- varjag 9y agoNo I don't use PuTTY. Also, I'm aware what you can do with C macros, doesn't mean you should do it. See my sister comment.
- murftown 9y agoI 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.