Cloak icon indicating copy to clipboard operation
Cloak copied to clipboard

Wiki page Is the C preprocessor Turing complete? should be more unequivocally no.

Open wyattscarpenter opened this issue 5 years ago • 2 comments

Hi, I'm quite enjoying the C preprocessor advice on your wiki! It's quite good. However, https://github.com/pfultz2/Cloak/wiki/Is-the-C-preprocessor-Turing-complete%3F beats around the bush a lot, but it should really start with "No." and end with "No." and contain discussion in between those statements.

The most important characteristic of the Turing machine is that you cannot solve the halting problem, whereas in C preprocessor you can always solve the halting problem: "yes".

The cpp was specifically designed not to be Turing complete. This is to avoid a host of issues that come with having a Turing complete language (mostly: it is very easy to accidentally create infinite loops). To avoid these problems, the cpp was "weakened" to be strongly normalizing, see https://en.wikipedia.org/wiki/Normalization_property_(abstract_rewriting). In particular, the cpp seems to be primitive recursive.

I wish you luck in revising the wiki page, and in all your endeavors. Thank you for your time.

wyattscarpenter avatar Jun 23 '20 19:06 wyattscarpenter

In that case, the C language (and all languages) are also primitive recursive, because all computers run out of memory, so there are always programs without a normal form: stack overflow. You're a genius.

In other words.. the folks who came up with the C preprocessor tried and failed to design it not to be Turing complete. Here is an implementation of a functional programming language in pure macros.

okovko avatar Dec 15 '20 10:12 okovko

Thanks for your interest, @okovko. There is indeed a surprisingly broad range of things non-Turing-complete languages can do! However, note that while(1) never terminates or runs out of memory.

wyattscarpenter avatar Dec 15 '20 15:12 wyattscarpenter