What is "plain old data" type (POD)?

  • Follow


Hello!

The term POD class type is used quite often in the standard, but I cannot
find a definition for it. 1.8 has a footnote that says that it stands for
"plain old data" and refers to 3.9, where there is no definition either. Can
anyone please explain this to me?

Best regards,

Matthias Hofmann




      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Matthias 12/10/2003 8:34:48 PM

"Matthias Hofmann" <hofmann@anvil-soft.com> wrote in message news:br7m0s$j3h$1@news1.nefonline.de...
 > Hello!
 >
 > The term POD class type is used quite often in the standard, but I cannot
 > find a definition for it. 1.8 has a footnote that says that it stands for
 > "plain old data" and refers to 3.9, where there is no definition either. Can
 > anyone please explain this to me?
 >
3.9 / 10 has the definition.  Anytime you see a described in a sentence and it is
italicized, then it is the definition.

   Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to member types (3.9.2), and cv-qualified
   versions of these types (3.9.3) are collectively called scalar types. Scalar types, POD-struct types,
   POD-union types (clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collec-tively
   called POD types.

Of course, this refers you to definitions of other things.   You probably get the first bunch fine.   POD-struct
is defined 9/4:

   A POD-struct is an aggregate class that has no non-static data members of type pointer to member,
   non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assign-ment
   operator and no user-defined destructor.

Which in turn uses the term aggregate defined in 8.5.1:

   An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or pro-tected
   non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).

So we can invert the whole thing by asking the question:

     WHAT KIND OF DATA TYPE ISN'T A POD:

Any data object of class type (which include structs and unions) that has:
     1.  Base classes,
     2.  User-declared constructors,
     3.  Private or protected non-static data members,
     4.  Base classes,
     5.  Virtual functions,
     6.  Non-static members of type pointer to member,
     7.  Any members that are not POD,
     8.  Any members that are references,
     9.  A user-defined copy-assignment operator [should say user-declared, defect in the standard], or
     10.  A user-defined destructor.   [also should say user-declared]
is not POD



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Ron 12/11/2003 11:42:38 AM


On 10 Dec 2003 15:34:48 -0500, "Matthias Hofmann"
<hofmann@anvil-soft.com> wrote:

> The term POD class type is used quite often in the standard, but I cannot
> find a definition for it. 1.8 has a footnote that says that it stands for
> "plain old data" and refers to 3.9, where there is no definition either. Can
> anyone please explain this to me?

3.9/10 defines POD types.  You will need to chase down POD-struct types
in clause 9.  9/4 states that a POD class is either a POD-struct or a
POD-union.  Chase some more to nail everything down.

In the end, it will look like a C struct with respect to non-static data
members and special function members.

John

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply John 12/11/2003 9:11:12 PM

On Wed, 10 Dec 2003 15:34:48 -0500, Matthias Hofmann wrote:

> Hello!
> 
> The term POD class type is used quite often in the standard, but I cannot
> find a definition for it. 1.8 has a footnote that says that it stands for
> "plain old data" and refers to 3.9, where there is no definition either. Can
> anyone please explain this to me?

It means types having trivial:
1. Constructors
2. Copy ctors
3. Destructors.


Regards,
-Dhruv.




      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Dhruv 12/12/2003 1:57:47 AM

Matthias Hofmann wrote:
> Hello!
> 
> The term POD class type is used quite often in the standard, but I cannot
> find a definition for it. 1.8 has a footnote that says that it stands for
> "plain old data" and refers to 3.9, where there is no definition either. Can
> anyone please explain this to me?

We had a discussion about this about 3 months ago.  Here's the thread:
<http://groups.google.com/groups?threadm=5d33192c.0308302225.7a987cce%40posting.google.com>

My definition was:

     POD (plain old data[1]) types are types whose instances can safely
     be copied as arrays of bytes, even if they have not been
     initialised[2].  Arithmetic, enumeration, pointer and pointer-to-
     member types are all POD types, as are arrays of POD types and
     const/volatile-qualified POD types[3].  Class, struct and union
     types are POD types if and only if they have no base classes, no
     user-declared constructors, copy-assignment operators or
     destructor, and no virtual functions; and if all their non-static
     data members are public, of POD types other than pointer-to-member
     types[4], and not const/volatile-qualified[5].

[1] Footnote 4.
[2] Section 3.9 paragraphs 2-4.
[3] Section 3.9 paragraph 10.
[4] Section 8.5.1 paragraph 1 and section 9 paragraph 4.  The ban on
    pointer-to-member members strikes me as an odd restriction,
    given that pointer-to-member types are themselves POD.
[5] I can't find a reference for this, but I am fairly confident that
    it is required.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Ben 12/12/2003 1:59:51 AM

4 Replies
619 Views

(page loaded in 0.1 seconds)

Similiar Articles:













7/22/2012 5:17:09 AM


Reply: