Re: using typedef to create aligned types

Daniel Glastonbury <[email protected]> Thu, 02 Dec 2004 11:42:48 +1000
Newsgroups gmane.games.devel.windows
Organization The Creative Assembly
Message-ID <[email protected]>
Daniel Glastonbury wrote:

> Andras Balogh wrote:
>
>> Let Fred be:
>>
>> class Fred {
>> public:
>>     int helloiamfred;
>> };
>>
>> then sizeof(Fred) will be 4
>>
>> but if I align the same class to 16 bytes:
>>
>> class __declspec(align(16)) Fred {
>> public:
>>     int helloiamfred;
>> };
>>
>> then sizeof(Fred) will be 16!!!
>>  
>>
> No it won't.

I've just been told by a friend that VS.Net spits out the following:
*
class Fred*
*{*
*public:*
*int helloiamfred;*
*};*
*class __declspec(align(16)) FredX {*
*public:*
*int helloiamfred;*
*};*
*int s1 = sizeof(Fred);*
*int s2 = sizeof(FredX);*

*s1 is 4, s2 is 16
*

His explanation was to do with operator new[] failing if it didn't 
adjust the size.

But my question is then, how does operator new cope with the typedef 
version?  Incorrectly?

cheers
DanG

-- 
Dan Glastonbury, Senior Programmer, The Creative Assembly
PO Box 883 Fortitude Valley, QLD, Australia. 4006
T: +617 3252 1359 W: http://www.creative-assembly.com.au
`Pour encourjay lays ortras'