public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/7201: Multiple inheritance from classes without data members wastes memory
@ 2002-07-03 11:06 markus
  0 siblings, 0 replies; 2+ messages in thread
From: markus @ 2002-07-03 11:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7201
>Category:       c++
>Synopsis:       Multiple inheritance from classes without data members wastes memory
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 03 11:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Markus L. Noga
>Release:        2.96 20000731 (Red Hat Linux 7.3 2.96-110), 2.95.3-5 (cygwin special)
>Organization:
>Environment:
2.96 20000731 (Red Hat Linux 7.3 2.96-110) and
2.95.3-5 (Windows XP Professional, cygwin special)
>Description:
Classes without data members occupy at least one byte,
even if they do not require a vtable pointer:
  class X1 {};
  -> sizeof(X1)==1

When inheriting from classes without data member, the mysterious bytes add up:
  class X2 {};
  class X3 : public X1, public X2 {};
  -> sizeof(X3)==2

They even persist when finally inheriting from a class
with data members:
  class X4 { int i; };
  class X5 : public X3, public X4 {};
  -> sizeof(X5)==8 (due to alignment)

Forcing packed structures does not change this.
>How-To-Repeat:
#include <iostream>

class X1 {};
class X2 {};
class X3 : public X1, public X2 {};
class X4 { int i; };
class X5 : public X3, public X4 {};

int main(int argc, char **argv) {
  cout << sizeof(X1) << endl;
  cout << sizeof(X2) << endl;
  cout << sizeof(X3) << endl;
  cout << sizeof(X4) << endl;
  cout << sizeof(X5) << endl;
  return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c++/7201: Multiple inheritance from classes without data members wastes memory
@ 2002-07-03 12:30 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-07-03 12:30 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, markus, nobody

Synopsis: Multiple inheritance from classes without data members wastes memory

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Wed Jul  3 12:30:21 2002
State-Changed-Why:
    fixed in the 3.0 series. Please refer to the abi
    document at http://www.codesourcery.com/cxx-abi/

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7201


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-03 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-03 11:06 c++/7201: Multiple inheritance from classes without data members wastes memory markus
2002-07-03 12:30 nathan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).