Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!orion.cf.uci.edu!uci-ics!schmidt@glacier.ics.uci.edu
From: schmidt@glacier.ics.uci.edu (Doug Schmidt)
Newsgroups: gnu.g++.bug
Subject: Re: size of empty classes
Message-ID: <21260@paris.ics.uci.edu>
Date: 18 Aug 89 20:44:04 GMT
References: <8908141613.AA23693@dsys.ncsl.nist.gov> <2271@csun.edu>
Sender: news@paris.ics.uci.edu
Reply-To: schmidt@glacier.ics.uci.edu (Doug Schmidt)
Distribution: gnu
Organization: University of California, Irvine - Dept of ICS
Lines: 49
In-reply-to: mx!cbcscmrs@csun.edu

In article <2271@csun.edu>, mx!cbcscmrs@csun writes:
>So g++ does not need or use it, the question to the writers (Michael???)
>why force it up to one?

In case you missed this before, here is Michael's answer to this
exact question from about 3 days ago:

----------------------------------------
Why speculate when you can have the answers?  Having GNU, we can
travel to the source code and find out:

from cplus-class.c (finish_struct):

  layout_type (t);
  /* C++: do not let empty structures exist.  */
  if (integer_zerop (TYPE_SIZE (t)))
    TYPE_SIZE (t) = TYPE_SIZE (char_type_node);

There is one byte reserved by this action on sparc and VAX, and two
bytes on m68k and i386.  Why not let empty structures exist?  Well,
for one thing, different implementations of malloc do different things
when called with zero for an argument.  Some systems will allocate a
chunk which gives the user zero size (but a four-byte overhead for
malloc).  Other systems will just return zero.  This means that

	empty *p = new p;

	...

	if (p == 0)
	  /* Ambiguous: maybe it is NULL, maybe it is `allocated'.  */

is highly non-portable.  I asked chatty why zero-sized structures were
desirable.  I have yet to receive an answer.  I do permit zero-sized
arrays, because they are useful when they are the last element in a struct:

	struct vector
	{
	  int len;
	  int elts[0];	/* If len == 0, no need to subtract 1 from size.  */
	};

Again, if a good case can be made for empty structures, I am willing
to be convinced.  But first you must convince me.
--
Master Swordsman speak of humility;             | schmidt@ics.uci.edu (ARPA)
Philosophers speak of truth;                    | office: (714) 856-4034
Saints and wisemen speak of the Tao of no doubt;
The moon, sun, and sea speaks for itself. -- Hiroshi Hamada