Implementationsdefiniertes Verhalten in C++
Ein Programm ist portabel, wenn es unter jeder C++ -Implementation das gewünschte Verhalten zeigt.
Implementationsdefiniertes Verhalten ist Verhalten, das von der zur Ausführung verwendeten C++ -Implementation abhängt und von ihr dokumentiert wird.
Es erlaubt Implementationen spezielles Verhalten bereitzustellen, das unter Aufgabe von Portabilität genutzt werden kann.
Beispielsweise ist der Wert von »::std::pow( 0, 0 )« oder der Wert von »INT_MAX« (mindestens 32767) implementationsdefiniert.
Ein portables Programm sollte implementationsdefiniertes Verhalten nicht nutzen, also beispielsweise nie »::std::pow( 0, 0 )« berechnen und für »INT_MAX« keinen größeren Wert als «32767» voraussetzen.
Ein nicht-portables Programm, das bewußt speziell für eine bestimmte Implementation geschrieben wird, kann implementationsdefiniertes Verhalten dieser Implementation nutzen.
- C -Standard
- "If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined."
- "The behavior of each of the functions in <math.h> is specified for all representable values of its input arguments, except where stated otherwise."
- "For all functions, a domain error occurs if an input argument is outside the domain over which the mathematical function is defined."
- "On a domain error, the function returns an implementation-defined value".