Re: memcpy() where assignment would do?
- From: neildferguson@xxxxxxxxxxx
- Date: Fri, 24 Aug 2007 19:43:26 -0700
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 =----
.
- Follow-Ups:
- Re: memcpy() where assignment would do?
- From: kuyper
- Re: memcpy() where assignment would do?
- References:
- memcpy() where assignment would do?
- From: kuyper
- memcpy() where assignment would do?
- Prev by Date: Re: simple lisp interpreter help needed
- Next by Date: Re: How to find the alignment requirements of a give type in the C99 standard?
- Previous by thread: Re: memcpy() where assignment would do?
- Next by thread: Re: memcpy() where assignment would do?
- Index(es):
Relevant Pages
|