Top "Undefined-behavior" questions

The unpredictable outcome of compiling or executing a program which breaks rules of the language neither compiler, interpreter nor runtime-system have to enforce.

Is signed integer overflow still undefined behavior in C++?

As we know, signed integer overflow is undefined behavior. But there is something interesting in C++11 cstdint documentation: signed integer …

c++ c++11 undefined-behavior integer-overflow
Detecting signed overflow in C/C++

At first glance, this question may seem like a duplicate of How to detect integer overflow?, however it is actually …

c++ c undefined-behavior signed integer-overflow
const member and assignment operator. How to avoid the undefined behavior?

I answered the question about std::vector of objects and const-correctness, and received a comment about undefined behavior. I do …

c++ constants undefined-behavior assignment-operator
Why is f(i = -1, i = -1) undefined behavior?

I was reading about order of evaluation violations, and they give an example that puzzles me. 1) If a side effect …

c++ language-lawyer undefined-behavior
Division by zero: Undefined Behavior or Implementation Defined in C and/or C++?

Regarding division by zero, the standards say: C99 6.5.5p5 - The result of the / operator is the quotient from the …

c++ c undefined-behavior divide-by-zero
Realloc on NULL-valued (or undefined) pointer

I was reading about realloc and got confused about a point mentioned there. Consider the code below: #include <stdio.…

c undefined-behavior realloc
Adding named item to named list - guaranteed to append to end of list?

When adding a named item to a list, is it guaranteed that the item will be added to the end …

r list undefined-behavior insertion named
Why does this for loop exit on some platforms and not on others?

I have recently started to learn C and I am taking a class with C as the subject. I'm currently …

c debugging undefined-behavior buffer-overflow
Is uninitialized local variable the fastest random number generator?

I know the uninitialized local variable is undefined behaviour(UB), and also the value may have trap representations which may …

c++ c undefined-behavior garbage
Accessing inactive union member and undefined behavior?

I was under the impression that accessing a union member other than the last one set is UB, but I …

c++ undefined-behavior language-lawyer unions