Jump to content
  • Advertisement

Archived

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

DeschutesCore

Need a small favor - 2 line conversion

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

OK, problem of the day. Working on creating a unit that loads 3ds files into a bsp tree and I have found a quickload unit on flipcode. Problem, I''ve converted about 70%, but I''m not following these two lines. chunkid := *(short*)(buffer); chunklength = *(long*)(buffer+2); chunkid is a shortint, chunklength is a long, and buffer is an array of char. What is it these lines are doing and how do you pull a shortint or a longint out of a dynamic array? Thanks in advance, Jason

Share this post


Link to post
Share on other sites
Advertisement
Well, since buffer is an array of char, it is essentially a pointer to a contiguous block of memory:

chunklength = *(long*)(buffer + 2);

buffer + 2 -> gives the pointer to the third char in the array
(long*) -> converts it to a pointer to a long
* -> derefrences it, so that it returns the value pointed to by the pointer.

J.W.

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!