Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!samsung!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!stl!robobar!ronald From: ronald@robobar.co.uk (Ronald S H Khoo) Newsgroups: comp.std.c Subject: Wanted: struct's address from member's address please. Message-ID: <1990Nov23.093458.24957@robobar.co.uk> Date: 23 Nov 90 09:34:58 GMT Organization: Robobar Ltd., Perivale, Middx., ENGLAND. Lines: 27 Can someone give me a pointer to relevant bits of the Standard please ? I'd like to know if 1) I can have a strictly conforming portable function that returns the address of a structure, given the address of a member of said structure, 2) Is this function the one I want ? (and is it strictly conforming?) #include /* typedefs to define type1 and type2 */ struct foo { type1 first_bit; type2 second_bit; }; struct foo * func(type2 *arg) { return (struct foo *) ((char *)arg - offsetof(struct foo, second_bit)); } -- ronald@robobar.co.uk +44 81 991 1142 (O) +44 71 229 7741 (H)