Path: utzoo!attcan!uunet!pilchuck!ssc!happym!polari!rlb From: rlb@polari.UUCP (rlb) Newsgroups: comp.lang.c++ Subject: Re: classes with no data members Summary: Can pointer to empty class be NULL... Keywords: sizeof,empty classes,new Message-ID: <472@polari.UUCP> Date: 9 Jun 88 18:56:19 GMT References: <464@polari.UUCP> <7943@alice.UUCP> <470@polari.UUCP> <10399@sol.ARPA> Organization: Polarserv, Seattle WA Lines: 20 In article <10399@sol.ARPA>, crowl@cs.rochester.edu (Lawrence Crowl) writes: > between them without having pointers that point somewhere? In essence, by > using a NULL pointer, you have taken away my ability to do: > > p = new empty ; > q = new empty ; > if ( p != q ) .... > Good point, which I had not thought of. This seems to prove that "new" must allocate space for an object of size zero, even if the host system "malloc" does not. To sum up, an implementation which wishes "empty" classes to occupy no space, must generate unique addresses for each such object (whether automatic or static) and must require the "new" operator to return unique addresses for objects of sizeof zero. Such an implementation is a bit iffy; since the language manual doesn't specify the behaviour of "new" with a zero arg, user versions may break the implementation. The alternative appears vastly easier and I assume all existing implementations take it: simply waste a byte of storage for each empty class.