4 ms·
Has anyone here tried to use m4 as a CPP replacement?
by bangonkeyboard 8y ago
Has anyone here tried to use m4 as a CPP replacement?
- rwmj 8y agoGood christ no, m4 is one of the worst macro preprocessors. If you're going to preprocess C code then you should use something which is aware of the syntax of C (analogous to camlp4 for OCaml). There are a bunch of "LISP macro for C" projects out there.
- bangonkeyboard 8y agoThe reason I even considered m4 is its ubiquity; since it's mandated by POSIX, it wouldn't be another external build dependency if I wanted more powerful (but more painful) preprocessing.
- fao_ 8y agoIf you're after POSIX compliance I'd use sed(1) and dc(1) before I touched m4(1)
- jan666 8y agoI just signed up to respond to this. So... ...First Post! (of mine anyway). OK, 20 years ago I went to a talk by Stroustrup in Cambridge, UK. He critiqued C and said there were better macro processors available than CPP. After the talk I went up and asked him what he was referring to, and he said M4. So I learnt it and haven't regretted it. I've used it in non-C projects quite extensively. tl;dr I've reasonable experience using M4 and from that I strongly disagree with you objection. Stroustrup moreso. Yes, it's weird, but very capable. It lacks named parameters but I can live with that for what it does give me, which is arbitrary blocks of code without '\' at the end of every line, and recursion which is the biggie. But diversions, which allow you to 'put aside' some code until later, which are pretty good and there's loads more stuff. May I suggest you give it another try before dismissing it.