[MUD-Dev] Re: Variable-sized structures in C (was: Naming and Directories)

Ola Fosheim Grøstad <olag@ifi.uio.no> Ola Fosheim Grøstad <olag@ifi.uio.no>
Mon Mar 22 22:03:56 CET 1999


"T. Alexander Popiel" wrote:
> As suspected, this is not fully portable.  (It also won't compile
> due to redeclaration of n, but that's minor.)

None of my code (on this list) will compile :-). People should write
their own code.

> The "proper" way
> to do it is:
> 
> struct node {
>   object *obj;
>   node *l,*r;
>   const char key[MAX_KEY_BUFFER_SIZE];
> };
[...]
> This approach eliminates nasty pointer math, prevents problems
> caused by allocating larger than the struct definition (which
> can blow up on segmented architectures)

Really?? Good to know. That's a good reason to do as you say.
Unfortunately you now risk getting some extra padding bytes which the
C-compiler adds to the size of struct node in order to make it aligned in
arrays, which was what I tried to generally avoid in the first place! :-/
However, it is probably worth it for the above mentioned reasons. (and
can be avoided if you know your target)

--
Ola Fosheim Groestad,Norway      http://www.stud.ifi.uio.no/~olag/


_______________________________________________
MUD-Dev maillist  -  MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev




More information about the mud-dev-archive mailing list