On Wed, Feb 21, 2001 at 05:13:35PM +0100, Poul-Henning Kamp wrote:
> In message <[EMAIL PROTECTED]>, Warner Losh writes:
> >In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes:
> >: Likewise if the first member were a more complex data type, but
> >: nevertheless the same between the different structures.
> >: 
> >: It seems safe to me, but I can't explain why :-)
> >
> >It is obfuscated 'C', but it is safe.  The standard requires that
> >(void *) &foo == (void *) &foo->s and that if s were a complex
> >structure that it be laid out the same in all instances of s.  So I
> >think that it is "safe" to do that.
> 
> Safe, but stupid, since type-safety is lost when doing so.

Type-safety is a cruch for the weak-minded.

:-)

But seriously I think that for the purpose of building a utility
function for use by qsort or similar, using a union just for such
a purpose is more obfuscated.

   struct nothing_much_in_common_really {
        const char *s;
        union {
              struct foo foo;
              struct bar bar;
        } u;
   };

But if there is a better way, I'm all ears :-)

Cheers,
-- 
Jacques Vidrine / [EMAIL PROTECTED] / [EMAIL PROTECTED] / [EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to