Topic: new POD and about POD?


Author: "Markus Mauhart" <mmauhart@ping.at>
Date: 1999/09/24
Raw View
> Masao Morita wrote:
> >=20
> > But I can not find the exact difinition of POD(Plain Old Data).
> > (I'm afraid of F.A.Q. but,) Say!

But the definition of "POD type" is still missing:

Q: What means "POD type" ?
A: (3.9 Types [basic.types], par. 10 (p. 52))
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 collectively called POD types.

To be complete also the other definitions from ISO+IEC+14882-1998.pdf:

Q: What means "POD class" or "POD-struct" or a "POD-union" ?
A: (9 Classes [class], par. 4 (p. 149))
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.
Similarly, a POD-union is an aggregate union 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 assignment
operator and no user-defined destructor.
A POD class is a class that is either a POD-struct or a POD-union.

Q: What means "aggregate" ?
A: (8.5.1 Aggregates [dcl.init.aggr])
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).

Note: "or a class (clause 9)" includes 'struct', 'class' and 'union'.
---
[ 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              ]





Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/09/23
Raw View
Greg Comeau wrote:
>
> In article <37E65584.165BFE7F@physik.tu-muenchen.de> Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
> >Masao Morita wrote:
> >> Consider the following:
> >>
> >>   struct POD {};                   // #1
> >>   struct PODwC { const int* cp; }; // #2
> >>
> >>   int main() {
> >>     POD* const podp = new POD;     // #3
> >>     PODwC* podwcp = new PODwC;     // #4
> >>   }
> >...
> >#4 should be rejected, though.
>
> I don't see which part of #4 you have a problem with.

Reading the class definition of PODwC ;-)

Indeed, #4 should be accepted as well, since - despite its name -
PODwC doesn't contain any const member. Sorry.
---
[ 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              ]





Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1999/09/20
Raw View
Masao Morita wrote:
>
> I am attempting to understand 5.3.4 p15 [expr.new]
>
>  A new expression that creates an object of type T initializes that
>  object as follows:
>   If the new initializer is omitted:
>     If T is a (possibly cv qualified) non POD class type, ...
>     Otherwise, the object created has indeterminate value. If T is a
>      const qualified type, or a (possibly cv qualified) POD class type
>      (or array thereof) containing (directly or indirectly) a member of
>      const qualified type, the program is ill formed;
>
> But, I can not understand exactly.
> Consider the following:
>
>   struct POD {};                   // #1
>   struct PODwC { const int* cp; }; // #2
>
>   int main() {
>     POD* const podp = new POD;     // #3
>     PODwC* podwcp = new PODwC;     // #4
>   }
>
> At first, does POD-type include no member struct? If so,
> The compiler should complain that both #3 and #4 are illegal.
> Is that right?

No. In #3, you allocate a new non-const POD.
The fact that you use the pointer obtained by new to
initialize a const pointer to POD (not even a pointer
to const POD - but it doesn't matter anyway) is completely
irrelevant.

#4 should be rejected, though.
As should be the following:

typedef POD const cPOD;
cPOD* podp = new cPOD;

>
> The standard document sometimes says, if type is POD or not, the behaviour
> would be change.
> But I can not find the exact difinition of POD(Plain Old Data).
> (I'm afraid of F.A.Q. but,) Say!

Well, I can only quote CD2:

CD2, 9 [class]/4:
  [...] A POD-struct2) 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  assignment  operator  and no user-defined
  destructor.  Similarly, a POD-union is an aggregate union 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  assignment  operator and no user-defined destructor.  A
  POD class is a class that is either a POD-struct or a POD-union.

[...]

  _________________________
  2) The acronym POD stands for "plain ol' data."

Aggregate is defined in

CD2, 8.5.1 [dcl.init.aggr]:

1 An aggregate is an array or a class (_class_)  with  no  user-declared
  constructors  (_class.ctor_),  no private or protected non-static data
  members (_class.access_), no base classes  (_class.derived_),  and  no
  virtual functions (_class.virtual_).

[...]
---
[ 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              ]





Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1999/09/20
Raw View
Christopher Eltschka wrote:
>
> Well, I can only quote CD2:
>
> CD2, 9 [class]/4:
>   [...] A POD-struct2) 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  assignment  operator  and no user-defined
>   destructor.  Similarly, a POD-union is an aggregate union 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  assignment  operator and no user-defined destructor.  A
>   POD class is a class that is either a POD-struct or a POD-union.
>
> Aggregate is defined in
>
> CD2, 8.5.1 [dcl.init.aggr]:
>
> 1 An aggregate is an array or a class (_class_)  with  no  user-declared
>   constructors  (_class.ctor_),  no private or protected non-static data
>   members (_class.access_), no base classes  (_class.derived_),  and  no
>   virtual functions (_class.virtual_).

A good rule of thumb is that a POD class is anything you can do with a
struct in C, with the possible addition of static members, since the latter
don't actually appear in instances of the class.

--

Ciao,                       Paul D. DeRocco
Paul                        mailto:pderocco@ix.netcom.com
---
[ 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              ]





Author: comeau@panix.com (Greg Comeau)
Date: 1999/09/21
Raw View
In article <37E65584.165BFE7F@physik.tu-muenchen.de> Christopher Eltschka <celtschk@physik.tu-muenchen.de> writes:
>Masao Morita wrote:
>> Consider the following:
>>
>>   struct POD {};                   // #1
>>   struct PODwC { const int* cp; }; // #2
>>
>>   int main() {
>>     POD* const podp = new POD;     // #3
>>     PODwC* podwcp = new PODwC;     // #4
>>   }
>...
>#4 should be rejected, though.

I don't see which part of #4 you have a problem with.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
     Producers of Comeau C/C++ 4.2.38 -- NOTE 4.2.42 BETAS NOW AVAILABLE
    Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
                *** WEB: http://www.comeaucomputing.com ***


[ 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              ]






Author: m-morita@trc.rwcp.or.jp (Masao Morita)
Date: 1999/09/20
Raw View
I am attempting to understand 5.3.4 p15 [expr.new]

 A new expression that creates an object of type T initializes that
 object as follows:
  If the new initializer is omitted:
    If T is a (possibly cv qualified) non POD class type, ...
    Otherwise, the object created has indeterminate value. If T is a
     const qualified type, or a (possibly cv qualified) POD class type
     (or array thereof) containing (directly or indirectly) a member of
     const qualified type, the program is ill formed;

But, I can not understand exactly.
Consider the following:

  struct POD {};                   // #1
  struct PODwC { const int* cp; }; // #2

  int main() {
    POD* const podp = new POD;     // #3
    PODwC* podwcp = new PODwC;     // #4
  }

At first, does POD-type include no member struct? If so,
The compiler should complain that both #3 and #4 are illegal.
Is that right?

The standard document sometimes says, if type is POD or not, the behaviour
would be change.
But I can not find the exact difinition of POD(Plain Old Data).
(I'm afraid of F.A.Q. but,) Say!

I think POD-type is for the compatibility of C-struct. Is that right?
therefore, as a condition,
There is no virtual member function.
There is no virtual base class.
There is no static member object.
There is no non-POD type object

All of my comprehension to POD-type is above.

Some questions will come on my mind.
Does POD-type have a base class?
Does POD-type have a member fucnction?
Does POD-type have a construcor?

M. Morita
---
[ 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              ]