~Rick wrote:
> On Dec 24, 2009, at 1:40, "Peter Nilsson" <[email protected]>  
> wrote:
>>  union myarray
>>  {
>>    unsigned char as_char[128];
>>    short as_short[128 / sizeof(short)];
>>    int as_int[128 / sizeof(int)];
>>  } myarray;
>>
>> But if you want to read 2 or 4 byte integers, you may be
>> better off simply reading 2 or 4 bytes from the character
>> array and constructing the integers.
>>
>> -- 
>> Peter
> 
> I've always ordered unions from the largest sized elements tithe  
> smallest in order to avoid alignment issues -- or, align the entire  
> union on a specific boundary. Is that not necessary?
> 
> ~Rick

Not necessary.  A union is the size of the largest element.  I can't 
think of any reason that there would there be alignment issues in the 
first place.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to