fbpx
Wikipedia

As-if rule

The standard for the C++ programming language allows compilers for this language to apply any optimizing[1] transformation to a program during compilation, provided that such optimizations make no change in the "observable behavior" of the program, as specified in the standard; this mostly means that any actions the program performs on its environment occur in the specified order. This rule is commonly referred to as the as-if rule.[2]

The rule has three main exceptions in which behavior-changing optimizations are permitted. The first is that programs exhibiting undefined behavior are exempt; since the observable behavior is not well-defined anyway, any transformation is valid. The other two exceptions concern the copying of objects, and are called copy elision and the return value optimization.

The effect of the as-if rule depends on the specific compiler implementation. As an example, in the Microsoft C++ compiler, it causes omission of certain optimizations such as instruction reordering around calls to library functions, since such calls may cause input/output actions or accesses to memory locations marked volatile, and changes in the order of those change observable behavior.[3]

The as-if rule is not specific to C++; many other programming languages, including C, Rust, Go, Ocaml, etc. have a similar rule, to permit optimization (notably inlining).

References Edit

  1. ^ “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid” Matt Godbolt CppCon2017 talk (September 29th, 2017)
  2. ^ As-if rule on Cppreference, retrieved in April 2018
  3. ^ Brais, Hadi (May 2015). "Compilers – What Every Programmer Should Know About Compiler Optimizations, Part 2". MSDN Magazine. Microsoft.


rule, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, news, newspapers, books, scholar, jstor, january, 2016, learn,. This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources As if rule news newspapers books scholar JSTOR January 2016 Learn how and when to remove this template message The standard for the C programming language allows compilers for this language to apply any optimizing 1 transformation to a program during compilation provided that such optimizations make no change in the observable behavior of the program as specified in the standard this mostly means that any actions the program performs on its environment occur in the specified order This rule is commonly referred to as the as if rule 2 The rule has three main exceptions in which behavior changing optimizations are permitted The first is that programs exhibiting undefined behavior are exempt since the observable behavior is not well defined anyway any transformation is valid The other two exceptions concern the copying of objects and are called copy elision and the return value optimization The effect of the as if rule depends on the specific compiler implementation As an example in the Microsoft C compiler it causes omission of certain optimizations such as instruction reordering around calls to library functions since such calls may cause input output actions or accesses to memory locations marked volatile and changes in the order of those change observable behavior 3 The as if rule is not specific to C many other programming languages including C Rust Go Ocaml etc have a similar rule to permit optimization notably inlining References Edit What Has My Compiler Done for Me Lately Unbolting the Compiler s Lid Matt Godbolt CppCon2017 talk September 29th 2017 As if rule on Cppreference retrieved in April 2018 Brais Hadi May 2015 Compilers What Every Programmer Should Know About Compiler Optimizations Part 2 MSDN Magazine Microsoft nbsp This programming language related article is a stub You can help Wikipedia by expanding it vte Retrieved from https en wikipedia org w index php title As if rule amp oldid 1111406105, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.