What the language definition does not say.
The C++ standard defines several kinds of not-fully specified things:
Implementation-defined (§1.9.2):
Unspecified behavior (§1.9.3):
Undefined behavior (§1.9.4):
A choice made by the compiler, which must be documented.
// Maximum value of a double: double d = 6e307; cout << d << '\n' << d*2 << '\n' << d*3;
6e+307 1.2e+308 inf
// Signed overflow: short s = 32767; cout << ++s;
-32768
// Character set used: cout << "\x41\x53\x43\x49\x49\x0a";
ASCII
// Size of variables: cout << sizeof(int) << '\n';
4
// Shifting a signed value right: cout << (-1 >> 4) << '\n';
-1
// Calling system(): system("date");
Fri Nov 22 02:42:47 MST 2024
A choice made by the compiler, need not be documented or consistent.
// Comparing addresses of different objects: int a,b; cout << boolalpha << (&a < &b);
false
// Order of evaluation of an expression (mostly): int foo() { cout << "foo\n"; return 0; } int bar() { cout << "bar\n"; return 0; } int main() { return foo()+bar(); }
foo bar
// Order of evaluation of function arguments: int foo() { cout << "foo\n"; return 1; } int bar() { cout << "bar\n"; return 1; } void ignore_arguments(int, int) { } int main() { ignore_arguments(foo(), bar()); }
bar foo
All bets are off! Anything can happen. Warnings are not required.
// Uninitialized value: int a[135]; a[30] = 0; cout << a[100] << '\n';
c.cc:4: warning: 'a[100]' is used uninitialized in this function 0
// Dereferencing a null pointer: cout << "This HAS to be displayed!\n"; int *p = nullptr; cout << *p << '\n';
SIGSEGV: Segmentation fault
// Shifting too far: int amount=35; cout << (1<<amount);
8
// Multiple writes to the same location: int a = 0; cout << ++a + ++a;
c.cc:3: warning: operation on 'a' may be undefined 4
// Multiple writes to the same location: int a=10; cout << (a=20) * (a=30);
c.cc:3: warning: operation on 'a' may be undefined 900
C++ is quite concerned about efficiency.
int
is implementation-defined so that the compiler
can use the natural size provided by the architecture.
double
is implementation-defined
so that the compiler can use the available hardware floating-point format.
C++’s attitude is “You break the rules, you pay the price.” It doesn’t hold your hand.