[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any basic cpp capability m4 cannot do?

From: Daniel Goldman
Subject: Re: Any basic cpp capability m4 cannot do?
Date: Sat, 10 May 2014 12:39:49 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

Hi Eric,

Thanks. I agree there is almost certainly a way to make an m4 macro to correctly escape "\"strings\" within strings". This could occur, eg with HTML. Now, if we moved to "\""strings" within strings\" within strings", that might be a little trickier for m4. :) It's probably still possible in some way, you would be a better judge.

Not to go too much on a tangent, I feel uncomfortable labeling m4 "Turing Complete". I am no expert, but based on my best understanding, "Turing Complete" refers to programming languages, and does not apply to pre-processors. I doubt one could write World of Warcraft, Microsoft Excel, or Linux OS in m4. To me, something "Turing Complete" should be able to do these things (perhaps incredibly slowly). And I don't think using m4 to generate C code counts. :)

I really like m4 so far, and appreciate the work you do to maintain it. But I think maybe it's going to far to say m4 is "Turing Complete" and "can do anything". Maybe it's enough that it's very useful, and can do needed pre-processing tasks.

As I have done the conversion, I have run into issues where I was tempted to ask the m4 group. Each time, after I read more, I found a way to do what I needed. So far, the conversion has resulted in much faster and easier-to-maintain processing, because I do not have to "pre-protect" and "post-expose" certain sequences from cpp.

Back to the original purpose of my post, another cpp/m4 difference that came to mind is that cpp will not substitute within a string. Of course, quote delimiters can be used in m4 to protect the macro from expansion. So this is acutally an m4 capability that cpp does not have, that m4 does permit macro expansion inside a string.


On 5/9/2014 5:30 AM, Eric Blake wrote:
On 05/08/2014 12:32 PM, Daniel Goldman wrote:

But if the sequence already contains strings, cpp "knows" to escape the
internal double quotes, m4 apparently does not:

But GNU m4 has the ability to regex replacement, so you can define your
m4 macro to use regexp to convert all " in the input to be \" in the
output, before adding your surrounding "" around the result.

Thanks again. Any other differences anyone might suggest, basic
capabilities cpp can do that m4 cannot do?

None.  m4 is Turing complete - and therefore it can do anything (just
not necessarily efficiently).  cpp can be abused to emulate Turing
completeness, although it is even hairier than m4's Turing completeness:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]