home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
- From: jss@lucid.com (Jerry Schwarz)
- Subject: Re: zero-length datatype
- Message-ID: <1992Sep10.003726.27140@lucid.com>
- Sender: usenet@lucid.com
- Reply-To: jss@lucid.com (Jerry Schwarz)
- Organization: Lucid, Inc.
- References: <TMB.92Sep7171355@arolla.idiap.ch>
- Distribution: comp
- Date: Thu, 10 Sep 92 00:37:26 GMT
- Lines: 41
-
- In article <TMB.92Sep7171355@arolla.idiap.ch>, tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
- |> C++ seems to be lacking in a data type that is guaranteed to be zero
- |> length.
-
-
- This understates the situation. C++ guarantees that no object
- will have size 0. For example
-
- struct Z { } ;
-
- may not have size 0.
-
- One reason for this constraint is to ensure that no two objects
- have the same address. In particular the elements of an array
- are always at different addresses.
-
- Z a[10] ;
-
- Without that constrain a[0],...,a[10] would all compare equal.
- (I know a[10] isn't a real member, but ANSI C guarantees that
- it is legal to take its address).
-
- Another is that new Z will never return the same adddress.
- Of course you could add this as an additional constraint on
- operator new if you wanted to.
-
- The constraint predates templates. Maybe it should be reconsidered.
- However that would require some consideration of the effect
- on existing code, and on common programming idioms. For example
- something like
-
- Z a[10] ;
- ...
- count = sizeof(a)/sizeof(Z)
-
- suddenly becomes a divde by zero.
-
- -- Jerry Schwarz
-
-
-
-