Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Curious

pointers

This topic is 6104 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

  
SCREENROW *Domain[MAXPLAYER];

for (int dm = 0; dm < MAXPLAYER; dm++)
{
   _int32 *pTmp = (_int32 *)vpScrw;
   _int32 Tmp = *(pTmp + dm); 
   Domain[dm] = (SCREENROW *)Tmp;
}
  
does anyone knows what this code does? vpScrw is a void pointer.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
i think its copying MAXPLAYER 32-bit integers from a buffer
pointed to by vpScrw to the Domain buffer

what the vpScrw buffer and the Domain buffer actually are or what algorithm this if from I don''t know I''ve never seen it before (although someone here probably has)

Share this post


Link to post
Share on other sites
Well, it could have been much cleaner with something like:

  
SCREENROW *Domain[MAXPLAYER];
_int32 *pTmp = (_int32 *)vpScrw;
for (int dm = 0; dm < MAXPLAYER; dm++)
{
_int32 tmp = *pTmp++;
Domain[dm] = (SCREENROW *)tmp;
}


or even combine the two statements in the for loop (less clear, perhaps). Or, given that vpScrw is actually a pointer to an array of SCREENROW pointers:

  
SCREENROW *Domain[MAXPLAYER];
SCREENROW **pTmp = (SCREENROW **)vpScrw;
for (int dm=0; dm<MAXPLAYER; dm++)
{
Domain[dm] = pTmp[dm];
};


which is clearer but slightly less efficient, depending on optimizations.

A few comments in the code would certainly make it clearer what the code was doing. Not stuff like ''assign tmp to *pTmp'', but something that describes what vpScrw points to (an array of pointers to SCREENROW structs) and what is happening (copying those pointers into Domain).

Style points DO count when coding, both for clarify and maintainability.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!