| rigorously binding or exacting; strict; severe - http://dictionary.com |
| stringent often means simply 'strict, strictly regulated' and also 'tight or constricted' and emphasizes the narrowness of what is permitted, while strict emphasizes the sternness with which something is enforced - http://thesaurus.com/ |
long double can be placed in memory starting at an address that is a multiple of four; but an object of type double can only be placed starting at an address which is a multiple of eight (in the above implementation). double is more exacting (more restricted) than that of long double; a double can't be placed at every address that a long double can be placed; or in other words, the alignment requirement of double is 'more stringent' than that of long double.long double is 4 everywhere; it may well be 12 on a different implementation (for instance one where a byte consists of 8 bits, sizeof(long double) is 12 and the architecture has 96-bit registers along with a 96-bit data bus).
double and long double are implementation-defined.long double provides is not less than the precision that a double provides. long double can hold is a (not necessarily proper) superset of the set of values that the type double can hold.long double to a double is a narrowing conversion.double and long double are two distinct fundamental types. | 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. |
| TheIdeasMan wrote: |
|---|
| even Scott Meyers hasn't figured out why one would need protected. |
| Anmol444 wrote: |
|---|
| Although you can just put the function in the base class public section its easier like that. |
|
|
std::alignment_of<double>::value.sizeof(double) == 24, sizeof( double[3] ) == 72.std::alignment_of<double>::value == 2 sizeof<double*> == 4,std::alignment_of<double*>::value == 8std::alignment_of<T>::value.sizeof(T) to portably get the size.std::alignment_of<T>::value to portably get the alignment.offsetof() macro (defined in cstddef) to portably get the offset of non-static member variables. |
|
type: double size: 8 alignment: 8 type: box size: 24 alignment: 8 type: box member: length offset: 0 type: box member: width offset: 8 type: box member: height offset: 16 type: char* size: 4 alignment: 4 type: candy_box size: 32 alignment: 8 derived class: candy_box base class: box offset: 0 type: candy_box member: contents offset: 24 |
|
|
| | 24
| |
| height | higher address
| | ^
| | |
|----------------| 16 |
| | |
| | |
| width |
| | lower address
| |
|----------------| 8
| |
| |
| length |
| |
| |
box* ---->|----------------| 0
// candy_box
|----------------| 32
| |
| |
| padding |
| |
| |
|----------------| 28
| |
| contents |
| |
| |
|----------------| 24
| |
| |
| |
| |
| |
| |
| |
| anonymous |
| base class |
| object of |
| type box |
| |
| |
| |
| |
| |
candy_box* ---->|----------------| 0 |
candy_box has 4 bytes padding added at the end to make the size an integral multiple of its alignment. candy_box objects every candy_box object must be aligned on an 8 byte boundary)