Need a small favor - 2 line conversion

Started by
2 comments, last by DeschutesCore 22 years, 8 months ago
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
Advertisement
I supposed it would help if I mentioned that I''m converting this to Delphi pascal.

Thanks again...
Jason
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.
J.W.

Thanks for the heads up. I''m still trying to translate it, but I''m beginning to understand what''s happening.

Thanks again,
Jason

This topic is closed to new replies.

Advertisement