From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-08-11 14:40:32
----- Original Message -----
From: "Martin Bonner" <martin.bonner_at_[hidden]>
Sent: Thursday, August 11, 2005 9:22 AM
Subject: Re: [boost] alignment problem in proposed any alternative
> ----Original Message----
> From: christopher diggins [mailto:cdiggins_at_[hidden]]
> Sent: 11 August 2005 14:00
> To: boost_at_[hidden]
> Subject: Re: [boost] alignment problem in proposed any alternative
>> 3.9(2) says:
>> For any complete POD object type T, whether or not the object holds a
>> valid value of type T, the underlying
>> bytes (1.7) making up the object can be copied into an array of char
>> or unsigned char.36) If the content of the array of char or unsigned
>> char is copied back into the object, the object shall subsequently
>> hold its original value.
>> This has nothing to do with void* and char*, but rather with all
>> This clearly implies char arrays are stringently aligned.
> Err, no it doesn't. It says that you can store the bits of a POD object
> into a char array, and then load the bits back into the same (correctly
> aligned) POD object.
> It does *NOT* say that you can use the address of the char array as if it
> were the address of the POD object.
> For example:
> #include <assert.h>
> int main()
> long pod = 3141L;
> char pad;
> char c[sizeof(pod)];
> memcpy( c, &pod, sizeof(pod) );
> pod = 42L;
> memcpy( &pod, c, sizeof(pod) );
> assert (pod == 3141L); // 3.9(2) requires this assert to pass.
> // nothing requires THIS assert to pass, and on some systems it fail
> // because c is not suitable aligned.
> assert ( *reinterpret_cast<long*>(&c) == 3141L );
> return 0;
Thank you for correcting me clearly and politely.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk