What is the precise relationship between C and it's abstract machine?

  • A+

I am reading "C in a nutshell" and there are alot of sentences similar to this one:

A statement specifies one or more actions to be performed such as assigning a value to a variable, passing control to a function, or jumping to another statement.

My question is what is the thing that "performs" these actions?

I have read here and there that C was defined to run on an abstract machine, so my guess is that the abstract machine is supposed to perform these actions, and the job of actual compilers like gcc is to ensure that if you evaluate a program mentally based on the way the abstract machine works then you would get the same result as when you actually run the object file generated by the compiler (ofcourse evaluating a program mentally is not possible in most cases, but I am speaking theoretically here).

So is the abstract machine supposed to interpret C code (after preprocessing) directly? Is C supposed to be translated to some intermediate code that the abstract machine interprets? What exactly is the relationship between the abstract machine and C?

What is the state of the abstract machine visible to programs? Only the main memory? If the abstract machine really interprets C code directly, how are declarations evaluated, how do they change the state of the abstract machine? This last series of questions only serves the purpose of giving you an idea of what I mean by precise relationship between C and it's abstract machine.


The abstract machine does not exist - it is, after all, literally abstract ("existing in thought or as an idea but not having a physical or concrete existence"). The abstract machine is an imaginary machine precisely follows the rules of the standard.

The C program is compiled by a compiler to a concrete machine which might (and usually does) have semantics distinct from that of the abstract machine. The actual machine might have things like speculative execution, out-of-order execution and parallelism.

A compliant compiler must produce an executable that when run, will have the observable behaviour as if the program was executed in the said abstract machine following the rules of the standard.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: