Archived

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

Need a small favor - 2 line conversion

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