As-if rule

as if
The standard for the C++ programming language allows compilers for this language to apply any optimizing 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.wikipedia
15 Related Articles

Copy elision

return value optimizationelision
The other two exceptions concern the copying of objects, and are called copy elision and the return value optimization.
The C++ language standard generally allows implementations to perform any optimization, provided the resulting program's observable behavior is the same as if, i.e. pretending, the program were executed exactly as mandated by the standard.

C++

C++ programming languageC++98C with Classes
The standard for the C++ programming language allows compilers for this language to apply any optimizing 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.

Compiler

compiledcompilerscompile
The standard for the C++ programming language allows compilers for this language to apply any optimizing 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.

Undefined behavior

undefinedundefined behaviourbehaviour is undefined
The first is that programs exhibiting undefined behavior are exempt; since the observable behavior is not well-defined anyway, any transformation is valid.

Microsoft Visual C++

Visual C++MSVCMicrosoft C
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.

Library (computing)

librarylibrariessoftware library
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.

Input/output

I/Ooutputinterface
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.

Programming language

programming languageslanguagedialect
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).

C (programming language)

CC programming languageC language
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).

Rust (programming language)

RustRust programming languageCargo
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).

Go (programming language)

GoGo programming languageGolang
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).

OCaml

MetaOCamlOCaml Package ManagerOPAM
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).

Optimizing compiler

compiler optimizationoptimizationoptimizations
The standard for the C++ programming language allows compilers for this language to apply any optimizing 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. 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).

Inline expansion

inlininginlinedinline
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).