1. 1

    Very weird and unnecessary complicated way. What about

    long x; int y; x = y; y = x; //assume their sizes are different
    

    Not to mention values can be in registers (and they may not be of the same size).

    1. 1

      I think that’s covered. I usually try to get people to diagram memory in boxes, so hopefully they’ll see the boxes are different sizes and comprehend the dangers of truncation.

      I wouldn’t worry about registers. They’re not relevant to understanding how a C program operates. The abstract machine in the C standard is a little vague, so modeling your program as a concrete machine with a stack and a heap is a useful clarification, but I would always study a program’s behavior in the context of a pure memory architecture.