The unpredictable outcome of compiling or executing a program which breaks rules of the language neither compiler, interpreter nor runtime-system have to enforce.
#include <iostream> using namespace std; int main() { int arr[3] = { 10, 20, 30 }; cout << arr[-2] << endl; cout &…
c++ arrays undefined-behaviorThe code below performs a fast inverse square root operation by some bit hacks. The algorithm was probably developed by …
c++ undefined-behavior gcc-warning strict-aliasing type-punningAs a newcomer to C, I'm confused about when casting a pointer is actually OK. As I understand, you can …
c casting undefined-behaviorLet's say I go to compile some poorly-written C++ source code that invokes undefined behavior, and therefore (as they say) "…
c++ language-lawyer undefined-behaviorI stumbled into this code for swapping two integers without using a temporary variable or the use of bitwise operators. …
c++ c swap undefined-behavior sequence-pointsA huge number of operations in C++ result in undefined behavior, where the spec is completely mute about what the …
c++ undefined-behaviorEDIT: This question was not intended as a forum for discussion about the (de)merits of undefined behavior, but that's …
c++ c language-lawyer undefined-behaviorI just checked the C++ standard. It seems the following code should NOT be undefined behavior: unsigned int val = 0x0…
c++ gcc assembly standards undefined-behaviorI am surprised to accidentally discover that the following works: #include <iostream> int main(int argc, char** argv) { …
c++ class constructor language-lawyer undefined-behaviorThe statement printf("%f\n",0.0f); prints 0. However, the statement printf("%f\n",0); prints random values. I realize I'm exhibiting …
c++ c printf implicit-conversion undefined-behavior