Solved

What's wrong with my memcpy statement?

Posted on 2004-04-01
4
381 Views
Last Modified: 2010-04-15
I have a seemingly simple problem. I just want to copy 100 bytes from my buffer to an absolute memory address of an ARM processor. Let's say that address is 0x100000.

long int AbsAddr = 0x2000000;
char *chbuffer[100]; // my buffer of 100 bytes

memcpy (AbsAddr, chBuffer, 100); // My statement

The C Compiler keeps complaining about incompatible cast. I understand AbsAddr is long int whereas *chbuffer is a char. But both of them are only pointers to char variables. Why pointers also need to have the same cast? I even test this statement and it still doesn't work:

char cTest = 0x01;
*AbsAddr = cTest; // Compiler also complains!




0
Comment
Question by:Volga
  • 2
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10738394
Hi Volga,

you can cast one pointer to another but mixing longs with pointers without a cast may be too much to ask ... try using void * instead

Sunnycoder
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 25 total points
ID: 10738398
Volga,

> But both of them are only pointers to char variables.
No both of them are not pointers .. AbsAddr is a long int and not a pointer ... When you say *AbsAddr, you are dereferencing a long int and not a pointer .... valid enough reason for compiler to complaint

Sunnycoder
0
 
LVL 84

Accepted Solution

by:
ozo earned 75 total points
ID: 10738447
long int AbsAddr = 0x2000000;
char chBuffer[100]; // my buffer of 100 bytes

memcpy ((char *)AbsAddr, chBuffer, 100);
0
 

Author Comment

by:Volga
ID: 10738550
ozo, thanks for the suggestion. At least you gave me a solution.

SunnyCoder, also thanks for your explanation, however I need a quick solution.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question