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.

When a float variable goes out of the float limits, what happens?

I remarked two things: std::numeric_limits<float>::max()+(a small number) gives: std::numeric_limits<float&…

c++ c floating-point undefined-behavior numeric-limits
Undefined behavior and sequence points reloaded

Consider this topic a sequel of the following topic: Previous installment Undefined behavior and sequence points Let's revisit this funny …

c++ undefined-behavior c++-faq sequence-points
In practice, why would different compilers compute different values of int x = ++i + ++i;?

Consider this code: int i = 1; int x = ++i + ++i; We have some guesses for what a compiler might do for …

c++ undefined-behavior
At what point in the loop does integer overflow become undefined behavior?

This is an example to illustrate my question which involves some much more complicated code that I can't post here. #…

c++ c undefined-behavior integer-overflow
Is the "struct hack" technically undefined behavior?

What I am asking about is the well known "last member of a struct has variable length" trick. It goes …

c undefined-behavior c89
Why does the enhanced GCC 6 optimizer break practical C++ code?

GCC 6 has a new optimizer feature: It assumes that this is always not null and optimizes based on that. Value …

c++ gcc compiler-optimization undefined-behavior
How to deal with clang's (3.9) -Wexpansion-to-defined warning?

clang 3.9 has added to -Wall a the warning -Wexpansion-to-defined, which produces macro expansion producing 'defined' has undefined behaviour in case …

c++ c clang undefined-behavior defined
Using GCC Undefined Behavior Sanitizer

Today I have read an article about GCC Undefined Behavior Sanitizer (ubsan). However, when I follow steps there (add -fsanitize=…

c++ gcc undefined-behavior undefined-reference ubsan
UBSan And Asan usage with GCC 4.9.2

I have compiled my application with -fsanitize=undefined option. How can I now test my application for undefined behavior? Also, …

c++ gcc undefined-behavior address-sanitizer ubsan