Re: memcpy() where assignment would do?



On Thu, 23 Aug 2007 08:27:34 -0700, kuyper <kuyper@xxxxxxxxxx> wrote:

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.

Here's a very off-topic possibility: the variables are defined as they are in
order to appear in particular segments of the linker's memory map, with
particular symbolic identification, so that the memory's addresses can be
associated with particular hardware I/O operations.

Neil


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.



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)
  • memcpy() where assignment would do?
    ... this declaration actually works on our compiler, ... this is not the most confusing part of the code. ... Am I missing something? ... plausible reason why the developer might write such bizarre code? ...
    (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)