Undefined Behavior: Ghosts in the Fog, or Boundaries of a Model?

https://hackernoon.imgix.net/images/sySM3ByE40PpGfuUTKKlXrkVuUL2-6j23boi.png

Let's Start

Programs are usually written to process input data and produce a result. Almost always — in a programming language. Every language comes with three fundamental concepts: syntax, semantics, and pragmatics.

More often than not, learning a language comes down to learning its syntax. And learning C often skips straight to pragmatics — talk about the "hardware" the compiled program will run on. Compiled. Passed compilation — must be correct. Syntactically — yes. Whether it will actually work correctly is a different question entirely.

It is from this gap between syntax and pragmatics that the ghosts of UB emerge. They frighten beginners and drive experienced programmers to write dozens of examples — pointing out the places where the ghosts are born. But the ghosts don't come from dark corners of the standard, and they're not the result of malicious intent on the part of compiler authors. They appear because...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more