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, must be documented.
sizeof(int)
double
int
overflows
'i'+1 == 'j'
'i'+8 == 'j'
A choice made by the compiler, need not be documented or consistent.
// Order of evaluation of an expression (mostly): int foo() { cout << "foo\n"; return 1; } int bar() { cout << "bar\n"; return 1; } int main() { cout << foo()+bar() << '\n'; }
foo bar 2
// 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.
int *p = nullptr; cout << "alpha\n"; cout << *p << '\n';
SIGSEGV: Segmentation fault
int n = 1067316150; cout << * (float *) &n << '\n';
1.234
int a = 0; cout << ++a + ++a << '\n';
c.cc:2: warning: operation on 'a' may be undefined 4
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.
Modified: 2017-01-28T22:24 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |