forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

memcpy Problem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ADePSP



Joined: 13 Jul 2006
Posts: 58

PostPosted: Sat Sep 30, 2006 1:14 am    Post subject: memcpy Problem Reply with quote

I'm having some problems with the memcpy function in C... I have a pointer to a chunk of data and I simply want to copy 2 bytes from it into a short...

See the code snippit,

Code:
char* ptrData;
unsigned short myShort;

ptrData = getData();

memcpy((char*)&myShort, ptrData, 2);

printf("ptrData = %d\n",(unsigned short)ptrData);
printf("myShort = %d\n",myShort);

You would expect the output values to be the same but they are not... What I get is,

ptrData = 23568
myShort = 36096

Can anyone see what i'm doing wrong and why myShort has the wrong number in it...?
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Sat Sep 30, 2006 1:33 am    Post subject: Reply with quote

first of all what is the declaration of getdata and why ptrdata is a char when you are using it to store a shorth?
second you can't do a simple myshort = *(unsigned short*)ptrdata (didn't test it :P)
Back to top
View user's profile Send private message Visit poster's website
ADePSP



Joined: 13 Jul 2006
Posts: 58

PostPosted: Sat Sep 30, 2006 3:32 am    Post subject: Reply with quote

weltall wrote:
first of all what is the declaration of getdata and why ptrdata is a char when you are using it to store a shorth?
second you can't do a simple myshort = *(unsigned short*)ptrdata (didn't test it :P)


It's ok, I worked it out... I was displaying the pointer of prtData rather than the data it contained... The memcpy did work and was correct... It was other mistakes that led me to believe otherwise...

Thanks anyway...
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Sat Sep 30, 2006 3:56 am    Post subject: Reply with quote

you should still remove the memcpy call bacause it's an unnedded lost of resources (it's still a function call)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group