From 8917050720136237552
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7317cd62b805354f
X-Google-Attributes: gidf78e5,public
From: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Subject: Re: What's POD?  Was: size of empty class?
Date: 1999/06/09
Message-ID: <375CDB83.72E68649@physik.tu-muenchen.de>#1/1
X-Deja-AN: 487335088
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <375609F3.1B7189E5@spots.ab.ca> <p6qu2spp41q.fsf@pandora.inst-inf-1.hu-berlin.de> <7j8r96$fqj$1@nnrp1.deja.com> <7j8v2k$l95$1@uuneo.neosoft.com> <375B4F0E.275FC699@spots.ab.ca> <7jhak7$9ot$1@pravda.ucr.edu>
X-Original-Date: Tue, 08 Jun 1999 10:59:47 +0200
X-Accept-Language: German/Germany, de-DE, German, de, en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 928897437 8696 128.250.29.16 (9 Jun 1999 03:03:57 GMT)
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN13ZiOEDnX0m9pzZAQHszwGAkBQQzAkSgrSMlyMX10fC9tsi5YgCXy7D js7uaSbTTACxDHqIMNe8wtVFhBdSk58L =b9NG
Mime-Version: 1.0
NNTP-Posting-Date: 9 Jun 1999 03:03:57 GMT
Newsgroups: comp.std.c++

Tom Payne wrote:
> 
> Maxwell Sayles <fysx@spots.ab.ca> wrote:
> : What does POD stand for?
> 
> As I understand it, the intent is that a C++ data type that is
> (recursively) a C data type is called a Plain Old Data (POD) type and
> is subject to the C layout rules.  Those layout rules are relaxed for
> non-POD types.  I'm not exactly sure how much space or time
> optimization that relaxation enables, however.

Well, the main reason is not saving of space, but adding extra
members for special purposes (esp. the vptr).
However, there are some obvious possible savings from the fact
that some reordering is allowed:

Look at this POD:

struct POD
{
  char a;
  int i;
  char b;
  char c;
  char d;
};

Since the POD rules demand ascending addresses, the layout on
a system with 4 byte aligned 4 byte ints looks is a___iiiibcd_
(_ denotes padding) and sizeof(POD)==12.

Now let's make it a non-POD:

struct NonPOD
{
  char a;
  int i;
private: // makes it non-POD
  char b;
  char c;
  char d;
};

In non-PODs, only the part between two access specifiers has the
restriction of ascending addresses; therefore this struct may be
layed out as abcdiiii with no padding and sizeof(NonPOD)==8.

I don't know if any compiler does that, though.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



