Xref: utzoo comp.lang.c:37679 comp.std.c:4550 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!cs.umn.edu!talon.UCS.ORST.EDU!usenet!ogicse!intelhf!ichips!iwarp.intel.com!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c,comp.std.c Subject: Re: increment casted void pointer -- ANSI? Message-ID: <3492@inews.intel.com> Date: 27 Mar 91 09:37:35 GMT Article-I.D.: inews.3492 References: <1991Mar8.165300.11692@zoo.toronto.edu> <288@nazgul.UUCP> <15589@smoke.brl.mil> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 33 In article <15589@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <288@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes: >-In article <1991Mar8.165300.11692@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >-/There is no way to say "pretend this variable has a different type" in C. >-The usual to do a 'type paint', which is to change the type of an object > >A strictly conforming method is to use a union type. Ouch! My ears just pricked up so hard I think I pulled my skull... Where in the std is it prohibited to fake unions by using a struct and externally prohibiting attempts to dereference a value that was superseded by one of a different type? It seems to say only that a union has to be at least large enough to hold it's member with the most bits, and to align members suitably, but not that it has to overlap types. The rationale parrots the "a pointer to a union, suitably cast, points to each member". Considering the latitude given a cast, this may mean that the pointer could be adjusted in byte-increments to point to the corresponding type's member. This implies strongly that overlap must occur if there is more than one member with the same type, but that doesn't buy too much "bit-paint". I only saw the one paragraph, though (ANSI X3.159-1989, sec. 3.5.2.1, p. 62, ll. 10-14), so I'd be glad if someone came up with more stringent, explicit delineation of this situation. --Blair "Time to make the donut holes..."