Representation of unions on capability machines

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Sep 17 09:47:44 AEST 1989


In article <29561 at news.Think.COM> barmar at 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.



More information about the Comp.lang.c mailing list