Solved

What's wrong with my memcpy statement?

Posted on 2004-04-01
4
380 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now