Re: [CODE] struct char_file_u mismatch

From: George Greer (greerga@circlemud.org)
Date: 07/22/01


On Mon, 23 Jul 2001, Michael Gesner wrote:

>> The structure can have arbitrary padding added by the compiler.
>
>That still beckons the question of what to do when I'm reading the pfile
>;o)
>
>I'm parsing the pfile to draw out player info for the website... If I use
>the figure 1292 I can draw out the number of players in the pfile... That
>works fine...

Until you modify it and the padding changes in subtle ways.

>I guess what I'm wondering...
>
>first of all... where does the compiler pad the struct...

Between fields.  It depends on your architecture how much is padded.  x86
seems to get 32-bit alignment.  So:

struct {
  short int foo;
  long in tbar;
}

takes 8 bytes.  2(short) + 2(pad) + 4(long)

>second... would I just be alright to scan through the struct and pull the
>data, and forget the padding...

If you get the offset of every variable in the structure you can access
them directly from the PHP:

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

You'll have to enumerate by hand though.

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST