Is the C99 preprocessor Turing complete?

前端 未结 4 1734
感情败类
感情败类 2020-11-27 12:26

After discovering the Boost preprocessor\'s capabilities I found myself wondering: Is the C99 preprocessor Turing complete?

If not, what does it lack to not qualify?

4条回答
  •  伪装坚强ぢ
    2020-11-27 12:54

    It's Turing complete within limits (as are all computers since they don't have infinite RAM). Check out the kinds of things you can do with Boost Preprocessor.

    Edit in response to question edits:

    The main limitation on Boost is the maximum macro expansion depth which is compiler-specific. Also, the macros that implement recursion (FOR..., ENUM..., etc.) aren't truly recursive, they just appear that way thanks to a bunch of near-identical macros. In the big picture, this limitation is no different than having a maximum stack size in an actually recursive language.

    The only two things that are really necessary for limited Turing-completeness (Turing-compatibility?) are iteration/recursion (equivalent constructs) and conditional branching.

提交回复
热议问题