Does this code print hello once or twice?
int main() { printf("hello\n"); }
Well, I think the answer lies in a more general understanding of what the standard describes, and not in the specific wording of the switch .
In accordance with the Execution of the program [intro.execution], the standard describes the behavior of an abstract machine that runs a program analyzed by C ++ grammar. It does not define what “abstract machine” or “performs” means, but it is assumed that they mean their obvious concepts of computer science, that is, a computer that goes through an abstract syntax tree and evaluates each part of it in accordance with the semantics described in the standard . This means that if you wrote something once, then when the execution reaches this point, it is evaluated only once.
A more relevant question is “when can an implementation evaluate something different than what is written in the program”? To do this, there is an as-if rule and a bunch of undefined behavior that allow the implementation to deviate from this abstract interpretation.
ybungalobill Jul 03 '15 at 12:35 2015-07-03 12:35
source share