Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site opus.UUCP
Path: utzoo!watmath!clyde!floyd!harpo!seismo!ut-sally!opus!rcd
From: rcd@opus.UUCP
Newsgroups: net.lang.c
Subject: Re: What Can't C Do?
Message-ID: <237@opus.UUCP>
Date: Thu, 15-Mar-84 21:37:28 EST
Article-I.D.: opus.237
Posted: Thu Mar 15 21:37:28 1984
Date-Received: Sat, 17-Mar-84 02:42:39 EST
References: <6900@unc.UUCP> <178@harvard.UUCP>
Organization: NBI, Boulder
Lines: 23

<>
 > While you're on the subject, what about == to compare two structures?
 > This is even more reasonable, in that structure assignment is supported...
Yet another bad idea.  This is much harder than it looks, for at least the
following reasons:

First, because of alignment constraints, structures may contain "holes" -
space allocated but not used.  Consider a 16-bit machine with a word
alignment constraint on ints and
	struct {int a; char b; int c;} . . .
In order to get both a and c aligned correctly, there's a one-byte hole
after b (assuming typical allocation of fields).  If the compiler is to
generate code to compare two instances of these structs, it has to skip
over the holes to avoid a spurious inequality result.  (Remember that even
though external variables can be initialized by the compiler - holes and
all - automatic variables may not be and usually aren't because of cost.)

A variant of the same problem occurs if the structure contains a union.
There is no way to know which part of a union is currently in effect, so
there's no way to know how much should be compared if the elements of the
union do not have the same length.
-- 
{hao,ucbvax,allegra}!nbires!rcd