memcpy() where assignment would do?



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.

.



Relevant Pages

  • Re: memcpy() where assignment would do?
    ... this declaration actually works on our compiler, ... this is not the most confusing part of the code. ... code for both ways of writing it. ... plausible reason why the developer might write such bizarre code? ...
    (comp.lang.c)
  • Re: memcpy() where assignment would do?
    ... this declaration actually works on our compiler, ... this is not the most confusing part of the code. ... plausible reason why the developer might write such bizarre code? ... particular symbolic identification, so that the memory's addresses can be ...
    (comp.lang.c)
  • Re: hmm..interesting
    ... I used to be a professional software developer on both Unix/Linux (all ... flavours) and Windows (writing CFD and Valve-train dynamics software, ... the fact that Visual Studio allows you to get away with fairly sloppy ... difficult to find a C compiler that *doesn't* have vendor-specific ...
    (comp.sys.acorn.hardware)
  • Re: Using the carry flag in standard C
    ... This is unnecessary if there is already an integer type that is double ... So while the above method gives the developer a deterministic ... are all simulated internally by the compiler. ... corresponds roughly to what we want *today*. ...
    (comp.std.c)
  • Re: pyjamas 0.7 released
    ... examples and a developer list. ... These days I prefer to stay with python ... wants to contribute absolutely anything, ask, and you get svn access - ... me, personally, i would be happy with the state the compiler was in, ...
    (comp.lang.python)