I ran across some old C code that was written something like this:
int array[NUM_ELEMENTS];
.. . .
memset(array, -1, sizeof(int)*NUM_ELEMENTS);
The code is filled with this idiom on memsets (and memcpys and ...).
I am trying to figure out why they just didn't code it this way:
memset(array, -1, sizeof(array));
The only thing I could think of is there was a time when
sizeof(somearray) didn't return the whole array's size. Anyone
remember anything like that from old, old C compilers? The oldest
reference I can find is from a 1988 printing of The C Programming
Language and even there sizeof works as today.
Of course the original authors may not have understood sizeof, too, I
suppose.