Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2005-01-12 13:12:42

Darryl Green wrote:

>Noah Stein <noah <at>> writes:
>>>n Behalf Of Jason Hise
>>> T * p = reinterpret_cast < T * > ( new char [ sizeof ( T ) ] );
>>Your Create() function in AllocateUsingNew isn't guaranteed to work for all
>>classes. The type of the singleton class might have alignment restrictions.
>>char has no alignment restrictions; therefore, the program may crash when
>>trying to initialize the singleton. I believe boost::aligned_storage is
>>your friend in this situation.
>Are you sure there is a problem here? Doesn't 5.3.4/10 allow this. The
>explanatory note reads in part:
>"...this constraint on array allocation overhead permits the common idiom of
>allocating character arrays into which objects of other types will later be
I have a question about a potential solution. Say I were to define a
union that contained a T, and then had a static instance of that union
lying around as the memory location to use for storage (using placement
new and explicit destruction to create and destroy the instance). Does
this result in undefined behavior (due to T not being a C-style struct),
or would it be legal C++?


Boost list run by bdawes at, gregod at, cpdaniel at, john at