Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wyattscarpenter opened this issue Jun 23, 2020 · 2 comments

Comments

@wyattscarpenter
Copy link

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.

@okovko
Copy link

okovko commented Dec 15, 2020

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.

@wyattscarpenter
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants