Unspecified behavior
In computer programming, unspecified behavior is behavior that may vary on different implementations of a programming language.[src] A program can be said to contain unspecified behavior when its source code may produce an executable that exhibits different behavior when compiled on a different compiler, or on the same compiler with different settings, or indeed in different parts of the same executable.[src] While the respective language standards or specifications may impose a range of possible behaviors, the exact behavior depends on the implementation and may not be completely determined upon examination of the program's source code.[src] Unspecified behavior will often not manifest itself in the resulting program's external behavior, but it may sometimes lead to differing outputs or results, potentially causing portability problems.[src]
In computer programming, unspecified behavior is behavior that may vary on different implementations of a programming language.[src] A program can be said to contain unspecified behavior when its source code may produce an executable that exhibits different behavior when compiled on a different compiler, or on the same compiler with different settings, or indeed in different parts of the same executable.[src] While the respective language standards or specifications may impose a range of possible behaviors, the exact behavior depends on the implementation and may not be completely determined upon examination of the program's source code.[src] Unspecified behavior will often not manifest itself in the resulting program's external behavior, but it may sometimes lead to differing outputs or results, potentially causing portability problems.[src] ==Definition== To enable compilers to produce optimal code for their respective target platforms, programming language standards do not always impose a certain specific behavior for a given source code construct.[src] Failing to explicitly define the exact behavior of every possible program is not considered an error or weakness in the language specification, and doing so would be infeasible.[src] In the C and C++ languages, such non-portable constructs are generally grouped into three categories: Implementation-defined, unspecified, and undefined behavior.[src] The exact definition of unspecified behavior varies.[src] In C++, it is defined as "behavior, for a well-formed program construct and correct data, that depends on the implementation." The C++ Standard also notes that the range of possible behaviors is usually provided.[src] Unlike implementation-defined behavior, there is no requirement for the implementation to document its behavior.[src] Similarly, the C Standard defines it as behavior for which the standard "provides two or more possibilities and imposes no further requirements on which is chosen in any instance".[src] Unspecified behavior is different from undefined behavior.[src] The latter is typically a result of an erroneous program construct or data, and no requirements are placed on the translation or execution of such constructs.[src] ==Implementation-defined behavior== C and C++ distinguish implementation-defined behavior from unspecified behavior.[src] For implementation-defined behavior, the implementation must choose a particular behavior and document it.[src] An example in C/C++ is the size of integer data types.[src] The choice of behavior must be consistent with the documented behavior within a given execution of the program.[src] ==Examples== ===Order of evaluation of subexpressions=== Many programming languages do not specify the order of evaluation of the sub-expressions of a complete expression.[src] This non-determinism can allow optimal implementations for specific platforms e.g.[src] to utilise parallelism.[src] If one or more of the sub-expressions has side effects, then the result of evaluating the full-expression may be different depending on the order of evaluation of the sub-expressions.[src] For example, given a = f(b) + g(b); , where f and g both modify b , the result stored in a may be different depending on whether f(b) or g(b) is evaluated first.[src] In the C and C++ languages, this also applies to function arguments.[src] Example: include int f() { std::cout The resulting program will write its two lines of output in an unspecified order.[src] In some other languages, such as Java, the order of evaluation of operands and function arguments is explicitly defined.[src] ==See also== Software portability Undefined behavior ==References==[src]
30 sentences · 30 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Unspecified behavior." encyclopegia.org, 2025, https://encyclopegia.org/wiki/unspecified-behavior. Accessed 25 November 2026.
Chicago
"Unspecified behavior." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/unspecified-behavior.
APA
encyclopegia.org. (2025). Unspecified behavior. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/unspecified-behavior
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON