I've run across some rather peculiar code; here are the relevant lines
that left me confused :
unsigned char cr_file[384];
unsigned char num_char[0];
Note: this declaration actually works on our compiler, and it appears
to be equivalent to giving a length of 1. The developer inserted
compiler options into the make file to turn off the relevant warning
messages. Sadly, this is not the most confusing part of the code. This
is an example of the confusing part:
num_char[0] = 1;
memcpy(&cr_file[147], num_char, 1);
num_char is used only in this fashion; its value after the call to
memcpy() has no bearing on the behavior of the program. I may be
missing something, but it seems to me that this code is therefore
exactly equivalent to
cr_file[147] = 1;
In fact, I would expect that some compilers would generate identical
code for both ways of writing it.
Am I missing something? If not, could someone at least suggest a
plausible reason why the developer might write such bizarre code? I
can't ask the developer, he died recently, which is how I became
responsible for this code.