home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13378 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.6 KB  |  74 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
  3. From: mcgrant@rascals.stanford.edu (Michael C. Grant)
  4. Subject: Re: zero-length datatype
  5. In-Reply-To: tmb@arolla.idiap.ch's message of 7 Sep 92 21:13:55 GMT
  6. Message-ID: <MCGRANT.92Sep7142456@rascals.stanford.edu>
  7. Sender: usenet@EE.Stanford.EDU (Usenet)
  8. Organization: Information Systems Laboratory, Stanford University
  9. References: <TMB.92Sep7171355@arolla.idiap.ch>
  10. Distribution: comp
  11. Date: 7 Sep 92 14:24:56
  12. Lines: 60
  13.  
  14. In article <TMB.92Sep7171355@arolla.idiap.ch>
  15. tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  16.  
  17.    Consider, for example, the following template class definition:
  18.  
  19.            template <class A,class B>
  20.            struct Bar {
  21.                    A x;
  22.                    B y;
  23.            };
  24.  
  25.  
  26.    Now, the straightforward declaration obviously fails.
  27.  
  28.            Bar<int,void> s;
  29.  
  30. I don't find this straightforward at all. It seems to me that a
  31. parametrized type is not properly parametrized if some of the types
  32. may contain a 'void' entry like that. Perhaps there should be two
  33. different parametrized types, one that contains B and one that
  34. doesn't, and sufficient conversion operators, if necessary, between
  35. the two of them.
  36.  
  37.    The following one compiles, but, unfortunately, "sizeof t" turns out
  38.    to be 8, not 4 (I believe the C++ definition makes an effort to ensure
  39.    that this is so):
  40.  
  41.    The non-existence of a zero length type is somewhat of a nuisance.
  42.  
  43. It is also quite necessary. Suppose that 'void' had zero length,
  44. and you instantiated
  45.  
  46. Bar<void,int>s.
  47.  
  48. Then the pointer to member A would have the same address as the pointer
  49. to member B! That should certainly not happen, since they are two different
  50. objects. The ARM has something quite specific to say about that.
  51.         
  52.    One fix might be to allow definitions of objects of type "void", give
  53.    them zero length, and introduce a single value for objects of type
  54.    "void", denoted "void()". Of course, there would be some minor
  55.    conflicts with the "function(void)" syntax, but those could be
  56.    resolved compatibly. Alternatively, another built-in special type
  57.    could be introduced, say, called "unit", that would be available
  58.    (only) after "#include <unit.h>".
  59.  
  60.  
  61. I certainly should not have to 'include' any definition of a built-in
  62. type.
  63.  
  64. I don't understand why those 4 bytes are causing you such a stink. Perhaps
  65. you could enlighten us as to why a truly zero length data type is even
  66. necessary? Also, I would like to see what templated member functions that
  67. operate on the above object would have to do to deal with the case of
  68. a 'void' type.
  69.  
  70. Michael C. Grant
  71.  
  72.  
  73.  
  74.