(Really addressing inside struct)Re: get size of malloc'd object

john at anasazi.UUCP john at anasazi.UUCP
Sun Jul 6 03:03:15 AEST 1986


A related problem that we have found with C alignment is this:
We have a structure with a number of structures contained within it. 
Because of linked list processing, we have a pointer to one of the
structures within, and we want to derive a pointer to the top of
the structure without LINT complaining, and in a truly portable way.
How can this be done? Many things have been tried without success
here at Anasazi. Example:

struct links {
   struct links *forward;
   struct links *backward;
};

struct foo {
   char bar;
   struct links snake;
   struct whocares junk;
   struct links lizard;
};

struct links *reptile;

Assume that reptile points to the lizard structure of a "foo" structure.
What construct allows one to do the following:

struct foo *iwish = (mystery function of reptile);

Example of a wrong solution:
struct foo *iwish = (struct foo *)((char *)reptile + (char *)0->lizard);

Any help would be appreciated.

-- 
John Moore (NJ7E)
{decvax|ihnp4|hao}!noao!mot!anasazi!john
{hao!noao|decvax|ihnp4|seismo}!mot!anasazi!john
mot!anasazi!john at SEISMO.CSS.GOV
(602) 861-7607 (day or evening)
7525 Clearwater Pkwy, Paradise Valley, AZ, 85253 (Home Address)

The opinions expressed here are obviously not mine, so they must be
someone else's.



More information about the Comp.unix mailing list