Need a small favor - 2 line conversion
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
I supposed it would help if I mentioned that I''m converting this to Delphi pascal.
Thanks again...
Jason
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement