Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Representation of unions on capability machines Message-ID: <11083@smoke.BRL.MIL> Date: 16 Sep 89 23:47:44 GMT References: <29561@news.Think.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <29561@news.Think.COM> barmar@think.UUCP (Barry Margolin) writes: -... I'd like to ask what the appropriate way to implement a union like -union pi { - char *ptr; - unsigned long num; -} x; -is on a machine that has separate data and capability pages. -Does C require that x.ptr and x.num actually occupy the same storage? No. -It doesn't appear to require that assigning to one member actually affect -the other member, because it is invalid to reference the other member -after such an assignment (so how could you tell if it were affected?). Right. -Does C require that &x.ptr == ((char *) *)&x.num? Yes. However, note that the constraint ("a pointer to a union object, suitably converted, points to each of its members") can be met by the implementation in numerous ways, since the conversion operation provides an opportunity for the implementation to recognize that unions need special handling.