From -7349106785965582671
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: <375E2D16.A2B88F6@physik.tu-muenchen.de>#1/1
X-Deja-AN: 487437546
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7j8v2k$l95$1@uuneo.neosoft.com> <375B4F0E.275FC699@spots.ab.ca> <375BE6CD.230C02F3@physik.tu-muenchen.de> <7jjjuk$ach$1@panix.com>
X-Original-Date: Wed, 09 Jun 1999 11:00:06 +0200
X-Accept-Language: German/Germany, de-DE, German, de, en
Content-Type: text/plain; charset=us-ascii
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN1487qwEuYhIxRhxAQF4lwIAjLYn+k2hxPAzErQMKhWEd+4EtQiprkLT /tMrd+VPcEbigZcLIbx7K9Fa8RnqLsd3q5rW6nKKM8U/ygaL2PaJhg== =yb9v
Mime-Version: 1.0
Newsgroups: comp.std.c++

Greg Comeau wrote:
> 
> In article <375BE6CD.230C02F3@physik.tu-muenchen.de> Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
> >[PODs are] not automatically initialized, except if they are static objects.
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Not what?  Please elaborate.

Not automatically initialized. That is, if you write

void foo()
{
  MyPOD var;
  // ...
}

you cannot expect to have defined values in var (there is the
possibility of "illegal" values, like signaling NaN in float).

Of course, if you initialize them explicitly (f.ex. with
"MyPOD var = { x, y, z };"), things are different; also,
static storage duration PODs are automatically initialized
to zero.

> 
> >You can think of PODs as just dead data lying around in memory,
> >instead of full objects which take care for themselves.
> 
> This might imply to some they are unconstructed or something, but the
> implication should be that they are dead data in the sense of C objects.

In some sense they _are_ unconstructed (unless they are static, or
explicitly initialized). Default construction (except for static vars
or explicit "Type()") is a do-nothing, and in addition you can use any
valid region of memory as POD without a need to first construct this
POD there:

POD* pPOD = (POD*)malloc(sizeof(POD));
*pPod = somePOD; // OK

NonPOD pNonPOD = (NonPOD*)malloc(sizeof(NonPOD);
*pNonPOD = someNonPOD; // Error: No NonPOD where the pointer points to
new(pNonPod) NonPOD; // Now construct a NonPOD in the given memory
*pNonPOD = someNonPOD; // OK: Now we have a NonPOD to assign to.

At least this is how I understand it. If I'm wrong, please
tell me.
---
[ 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              ]



