Jump to content
  • Advertisement
Sign in to follow this  
lomateron

moving array bits to another array of another type

This topic is 1711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have in C++

 

RAWMOUSE mouses[2];

char info[48];   // size of one RAWMOUSE is 24 bytes

 

I want to pass the bits of info to mouse and viceversa

Share this post


Link to post
Share on other sites
Advertisement

This is a really, really, really bad idea, and you should avoid it, but here's how it would work:

 

// Copy mouse data into info array
const char * pmouse = reinterpret_cast<const char *>(&mouses[0]);
std::copy(pmouse, pmouse + sizeof(RAWMOUSE * 2), &info[0]);
 
// Copy info array into mouse data
char * pmouse = reinterpret_cast<char *>(&mouses[0]);
std::copy(&info[0], &info[48], pmouse);

 

 

At the very least, use some static asserts to ensure that your RAWMOUSE size and the size of the info array are lined up correctly.

 

But yeah, you really just shouldn't do that. Depending on what you're trying to accomplish, there's basically guaranteed to be a better solution.

Share this post


Link to post
Share on other sites

what I am doing is sending the raw mouse input of 2 mouse to another computer using datagram sockets.

sometimes the send() will send incomplete data and will tell me how many bytes of the data has been sent and I have to calculate how much is left and send the rest

so I have to pass the RAWMOUSE array to a char array so when I see that there are lets say 4 bytes left to send I can send them:

 

char info[48];

char* pointer;

pointer=info;

send(pointer);

 

//then I find that 44 of the 48 bytes were sent

pointer+=44;

send(pointer); 

 

ooHH!!I just need to use da "pointer" with "mouses" sorry now i know how to do it!!!

char* pointer;

pointer=mouses;  //mouses!!!!!<---------------------------------

send(pointer);

 

//then I find that 44 of the 48 bytes were sent

pointer+=44;

send(pointer); 

Edited by lomateron

Share this post


Link to post
Share on other sites
Look into serialization. This approach is going to bite you sooner or later, and you may as well do it right :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!