> On my compiler VC++, the size is 8 bytes and its alignment is also 8.
Repeat: size, alignment and value-representation of
double
and
long double
are
implementation-defined.
Subject to the proviso that:
a. the precision that
long double
provides is
not less than the precision that a double provides.
(It
may be greater.)
b. the set of values that the type
long double
can hold is a (
not necessarily proper) superset of the set of values that the type
double
can hold.
> Also what does double have to do with long double?
Both are floating point types; due to the provisions
a. and
b. above,
the conversion from a
long double
to a
double
is a
narrowing conversion.
> Aren't they both completely different types???
They are two different types. However, they may (or may not) have the same object representation. Even if they happen to have the same object representation (the same value representation, the same size and the same alignment) on a particular implementation,
double
and
long double
are two distinct fundamental types.
> I really like making sure I know and understand it.
The basic idea is extremely simple; you are unnecessarily complicating it by trying to factor in completely irrelevant issues like size.
Object types have alignment requirements which place restrictions on the addresses at which an object of that type may be allocated. An alignment is an implementation-defined integer value representing the number of bytes between successive addresses at which a given object can be allocated. An object type imposes an alignment requirement on every object of that type
...
Alignments have an order from weaker to stronger or stricter alignments. Stricter alignments have larger alignment values. An address that satisfies an alignment requirement also satisfies any weaker valid alignment requirement.
...
Comparing alignments is meaningful and provides the obvious results:
— Two alignments are equal when their numeric values are equal.
— Two alignments are different when their numeric values are not equal.
— When an alignment is larger than another it represents a stricter alignment. |
Incidentally, the term '
more stringent alignment requirement' that I used earlier has the same meaning as the term '
stronger or stricter alignment' used by the IS.