Discussion:
What exactly is a POD type
(too old to reply)
Matthias
2005-02-19 10:19:25 UTC
Permalink
I searched the standard for an exact explanation of what "plain old
data" might be... I suppose, built-in types are POD. But what about this:

struct Data {
int a,b;
};

Is Data a POD type?
--
Regards,
Matthias
Andrey Tarasevich
2005-02-19 10:40:20 UTC
Permalink
Post by Matthias
I searched the standard for an exact explanation of what "plain old
struct Data {
int a,b;
};
Is Data a POD type?
...
Yes.

The definition of POD type is given in 3.9/10 and is partially based on
definition of "POD-class" given in 9/4, which is in turn based on the
definition of "aggregate" given in 8.5.1/1.
--
Best regards,
Andrey Tarasevich
fabioppp
2005-02-19 11:03:39 UTC
Permalink
Post by Matthias
struct Data {
int a,b;
};
Is Data a POD type?
...
Yes.
Another question...
Why offsetof macro may not work with non POD types?
And why pointer to members should?

--
fabioppp
Ron Natalie
2005-02-19 20:31:02 UTC
Permalink
Post by fabioppp
Another question...
Why offsetof macro may not work with non POD types?
And why pointer to members should?
...because the standard says so.

Poitner to members aren't just an offset by the way. They
have to work on polymorphic objects and hence need additional
information.
fabioppp
2005-02-20 00:22:48 UTC
Permalink
Post by Ron Natalie
Poitner to members aren't just an offset by the way. They
have to work on polymorphic objects and hence need additional
information.
The only problem I can figure out is multiple inheritance,
where the offset of a field has to be added with some other value.
With static offset there is no way to achieve this, while pointer to
member (because of the heaviest typing) can achieve this.
Ron Natalie
2005-02-21 13:36:23 UTC
Permalink
Post by fabioppp
Post by Ron Natalie
Poitner to members aren't just an offset by the way. They
have to work on polymorphic objects and hence need additional
information.
The only problem I can figure out is multiple inheritance,
where the offset of a field has to be added with some other value.
With static offset there is no way to achieve this, while pointer to
member (because of the heaviest typing) can achieve this.
In practice, that is the problem (virutal inheritance adds yet another
wrinkle).

I believe that at some point in setting down the rules, someone had
the idea that some kind of runtime access control might be useful and
hence put restrictions on things (offsetof, member ordering) that
relax the concept that classes are contiguous accross access specifiers.
John Carson
2005-02-19 10:41:46 UTC
Permalink
Post by Matthias
I searched the standard for an exact explanation of what "plain old
struct Data {
int a,b;
};
Is Data a POD type?
Yes. See the C++ FAQ:

http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7
--
John Carson
Matthias
2005-02-19 10:48:32 UTC
Permalink
Post by John Carson
Post by Matthias
I searched the standard for an exact explanation of what "plain old
struct Data {
int a,b;
};
Is Data a POD type?
http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7
The FAQ mention that POD types must not have constructors or a
destructor. I guess they mean /user defined/ ctor/dtor? Because the Data
struct above has a compiler generated ctor/dtor right? This would by
definition of the FAQ make it a non-POD type.
--
Regards,
Matthias
Ioannis Vranos
2005-02-19 11:34:50 UTC
Permalink
Post by Matthias
The FAQ mention that POD types must not have constructors or a
destructor. I guess they mean /user defined/ ctor/dtor?
Yes.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
E. Robert Tisdale
2005-02-19 20:40:12 UTC
Permalink
Post by Matthias
I searched the standard for an exact explanation of what "plain old
struct Data {
int a,b;
};
Is Data a POD type?
No.

Plain Old Data refers to built-in data types -- intrgral types:
signed and unsigned char, short int, int, long int, long long int
and floating-point types float, double and long double.
Andrey Tarasevich
2005-02-19 22:04:07 UTC
Permalink
Post by E. Robert Tisdale
...
Post by Matthias
I searched the standard for an exact explanation of what "plain old
struct Data {
int a,b;
};
Is Data a POD type?
No.
signed and unsigned char, short int, int, long int, long long int
and floating-point types float, double and long double.
...
Wrong. The types you mention are referred to as arithmetic types. All
arithmetic types are POD, but not all POD types are arithmetic.

The above struct is a POD-class, which makes it a POD type.
--
Best regards,
Andrey Tarasevich
Loading...