4 ms·
Around 26 years ago, I was working on some C code that was ported from assembler. It was too long ago to remember the actual bug, but I was stumped how a certai
by chrisbennet 13y ago
Around 26 years ago, I was working on some C code that was ported from assembler. It was too long ago to remember the actual bug, but I was stumped how a certain variable "C" was getting set. I wasn't set explicitly anywhere in the code.
It turns out that is was declared like this:
int A, B, C;
and it was being set something like this:
int* pA = &A; // pointer to contents of "A"
pA[2] = 3; // WTF?
A,B, and C where assumed to be contiguous in memory and the code was treating "C" like the 3rd item in an array starting at "A".