• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

What's wrong with my memcpy statement?

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
Volga
Asked:
Volga
  • 2
2 Solutions
 
sunnycoderCommented:
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
 
sunnycoderCommented:
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
 
ozoCommented:
long int AbsAddr = 0x2000000;
char chBuffer[100]; // my buffer of 100 bytes

memcpy ((char *)AbsAddr, chBuffer, 100);
0
 
VolgaAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now