Profile photo for Michael Veksler

It is common knowledge that C is Turing complete. For years I have believed this.

I have had bad experiences with “common knowledge” so let’s employ critical thinking, and write a Turing machine simulator in C.

  1. We need a state machine.
    Check. It is trivial to implement a state machine in C.
  2. We need an infinite tape, and a way to maintain a current position into it.
    Let’s examine some possibilities:
    1. RAM: Although RAM is finite, C does not seem to limit RAM size. RAM size is obviously just an implementation detail, not part of C.
      But is it?
      Pointers have to be convertible to size_t integers, i.e., pointers have a predefined size.
      The size is set at compile time. This means that we limit the tape to 2 ** num_bits(size_t) entries, which is not infinite. Even if we define size_t to have 1024 bits, it is still finite.
    2. Disk: It seems to be OK. C library function fseek() is needed to travel the tape on disk. Obviously, neither SEEK_SET nor SEEK_END will do, since they use long int for offset. Since long int has a predefined number of bits, the tape is finite from the start.

      I’m desperate, so I look into
      SEEK_CUR. With SEEK_CUR it is possible to do relative seeks, without limiting the position to fit long. This means that there is no limit to the tape length, from language perspective.

So, C does seem to be Turing complete, but only due to a loophole in fseek(). Without using the loophole of relative file seek, it would have not been Turing complete.

View 5 other answers to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025