Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: net.lang.c Subject: Re: (Really addressing inside struct) Message-ID: <2151@brl-smoke.ARPA> Date: Sat, 12-Jul-86 09:14:59 EDT Article-I.D.: brl-smok.2151 Posted: Sat Jul 12 09:14:59 1986 Date-Received: Sun, 13-Jul-86 06:58:06 EDT References: <165@daisy.UUCP> <334@valid.UUCP> <2206@peora.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 35 In article <403@anasazi.UUCP> john@anasazi.UUCP (John Moore) writes: -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); This is rather a strange way to do business, but I can answer the question: There is no guaranteed way to do what you're trying to do, therefore there should be no way to keep "lint" from complaining. However, the following should work for most C implementations: struct foo dummy; #define LIZ_OFFSET ((char *)&dummy.lizard - (char *)&dummy.bar) struct foo *iwish = (struct foo *)((char *)reptile - LIZ_OFFSET); What I would recommend instead is that you keep a pointer to the whole (struct foo) rather than to the lizard member, if your application permits. (You might need to add a (struct foo *) member to (struct links).)