C ++预处理程序元编程图灵完成了吗? [英] Is C++ preprocessor metaprogramming Turing-complete?

查看:111
本文介绍了C ++预处理程序元编程图灵完成了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道C ++模板元编程是图灵完成的.预处理器元编程是否也一样?

I know C++ template metaprogramming is Turing-complete. Does the same thing hold for preprocessor metaprogramming?

推荐答案

否. C ++预处理器不允许无限状态.您只有有限数量的开/关状态,以及一个包含堆栈.这使它成为下推式自动机,而不是图灵机(这也忽略了预处理器递归受限制的事实,而模板递归也受到限制).

No. The C++ preprocessor does not allow for unlimited state. You only have a finite number of on/off states, plus a include stack. This makes it a push-down automaton, not a turing machine (this ignores also the fact that preprocessor recursion is limited - but so is template recursion).

但是,如果您稍微修改一下定义,则可以通过多次调用预处理器来实现-通过允许预处理器生成重新调用预处理器的程序,并在外部循环,它是

However, if you bend your definitions a bit, this is possible by invoking the preprocessor multiple times - by allowing the preprocessor to generate a program which re-invokes the preprocessor, and looping externally, it is indeed possible to make a turing machine with the preprocessor. The linked example uses C, but it should be adaptable into C++ easily enough.

这篇关于C ++预处理程序元编程图灵完成了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆