What are all the common undefined behaviours that a C++ programmer should know about?
Say, like:
a[i] = i++;
NULL
pointermemcpy
to copy overlapping buffers.int64_t i = 1; i <<= 72
is undefined)int i; i++; cout << i;
)volatile
or sig_atomic_t
at the receipt of a signallong int
#if
expressionThe order that function parameters are evaluated is unspecified behavior. (This won't make your program crash, explode, or order pizza... unlike undefined behavior.)
The only requirement is that all parameters must be fully evaluated before the function is called.
This:
// The simple obvious one.
callFunc(getA(),getB());
Can be equivalent to this:
int a = getA();
int b = getB();
callFunc(a,b);
Or this:
int b = getB();
int a = getA();
callFunc(a,b);
It can be either; it's up to the compiler. The result can matter, depending on the side effects.