cc99language-lawyer

lvalue doesn't designate an object after evaluation?


C99 [Section 6.3.2.1/1] says

An lvalue is an expression with an object type or an incomplete type other than void; if an lvalue does not designate an object when it is evaluated, the behavior is undefined.

What does the part in bold mean? Can someone please explain it with an example?


Solution

  • Null pointers, pointers to deallocated objects and pointers to objects with automatic storage duration whose lifetime has already ended come to mind. Dereferencing these results in invalid lvalues; the undefined behaviour you will encounter most often are segfaults if you're lucky, and arbitrary heap or stack corruption if not.