Solved

What's wrong with my memcpy statement?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

746 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

10 Experts available now in Live!

Get 1:1 Help Now