Solved

What's wrong with my memcpy statement?

Posted on 2004-04-01
4
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
First character of input string truncated with scanf 3 116
Problem to ASCII 1 234
sameEnds challenge 3 194
C qsort compare function issue 6 70
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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 while-loops in the C programming language.

737 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