Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ncar!boulder!sunybcs!rutgers!columbia!douglass!dupuy From: dupuy@douglass.columbia.edu (Alexander Dupuy) Newsgroups: comp.lang.c++ Subject: Re: classes with no data members Message-ID: <5690@columbia.edu> Date: 10 Jun 88 22:25:16 GMT References: <470@polari.UUCP> <593@goofy.megatest.UUCP> Sender: nobody@columbia.edu Reply-To: dupuy@douglass.columbia.edu (Alexander Dupuy) Followup-To: comp.lang.c++ Organization: Columbia University Computer Science Dept. Lines: 36 In article <7943@alice.UUCP>, ark@alice.UUCP writes: > > The unsatisfying part is the statement that a pointer to an empty > class must point *somewhere*. I don't see why it has to point *anywhere*. In article <593@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: > >It doesn't have to point anywhere, since nothing will be there to >be pointed to. But pointers to two such objects should be distinguishable, >so you can't just use (foo*)0 for all of them. In fact, all >pointers of any types should be pairwize distinguishable. > >Did I miss the part where people said WHY they would want to have >pointers to empty structures? And why they could not begrudge a byte >or two of wasted space to accomplish this feat? > > > Dave J. On a system with demand-paged virtual memory, it is quite easy to have pointers which are distinguishable, but which don't point to anything which exists (in memory). Just have an empty page (in BSS, of course, so it doesn't take up disk space, either) which is used only as the target of pointers to empty classes, structs, and anything else which has zero size. If you have more than PAGESIZE zero sized structures, just reserve more empty pages. If you're feeling adventurous, you could even try using invalid pages (whatever they may be on your particular machine) so that you don't even waste usable virtual memory space. "I gotta whole lotta nuttin..." @alex -- inet: dupuy@columbia.edu uucp: ...!rutgers!columbia!dupuy