home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
- From: mcgrant@rascals.stanford.edu (Michael C. Grant)
- Subject: Re: zero-length datatype
- In-Reply-To: tmb@arolla.idiap.ch's message of 7 Sep 92 21:13:55 GMT
- Message-ID: <MCGRANT.92Sep7142456@rascals.stanford.edu>
- Sender: usenet@EE.Stanford.EDU (Usenet)
- Organization: Information Systems Laboratory, Stanford University
- References: <TMB.92Sep7171355@arolla.idiap.ch>
- Distribution: comp
- Date: 7 Sep 92 14:24:56
- Lines: 60
-
- In article <TMB.92Sep7171355@arolla.idiap.ch>
- tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
-
- Consider, for example, the following template class definition:
-
- template <class A,class B>
- struct Bar {
- A x;
- B y;
- };
-
-
- Now, the straightforward declaration obviously fails.
-
- Bar<int,void> s;
-
- I don't find this straightforward at all. It seems to me that a
- parametrized type is not properly parametrized if some of the types
- may contain a 'void' entry like that. Perhaps there should be two
- different parametrized types, one that contains B and one that
- doesn't, and sufficient conversion operators, if necessary, between
- the two of them.
-
- The following one compiles, but, unfortunately, "sizeof t" turns out
- to be 8, not 4 (I believe the C++ definition makes an effort to ensure
- that this is so):
-
- The non-existence of a zero length type is somewhat of a nuisance.
-
- It is also quite necessary. Suppose that 'void' had zero length,
- and you instantiated
-
- Bar<void,int>s.
-
- Then the pointer to member A would have the same address as the pointer
- to member B! That should certainly not happen, since they are two different
- objects. The ARM has something quite specific to say about that.
-
- One fix might be to allow definitions of objects of type "void", give
- them zero length, and introduce a single value for objects of type
- "void", denoted "void()". Of course, there would be some minor
- conflicts with the "function(void)" syntax, but those could be
- resolved compatibly. Alternatively, another built-in special type
- could be introduced, say, called "unit", that would be available
- (only) after "#include <unit.h>".
-
-
- I certainly should not have to 'include' any definition of a built-in
- type.
-
- I don't understand why those 4 bytes are causing you such a stink. Perhaps
- you could enlighten us as to why a truly zero length data type is even
- necessary? Also, I would like to see what templated member functions that
- operate on the above object would have to do to deal with the case of
- a 'void' type.
-
- Michael C. Grant
-
-
-
-