Re: A C++ question

"Victor R. Volkman" <[email protected]> Wed, 28 Jun 2006 11:55:27 -0400
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
1. Unions always align on the pickiest member of the union.  If you have union of char
and int, it will align on 2-byte.  Union of char, int, float on 4-byte.  Union of char, int, float, double on 8-byte.
2. Doubles are always 8-bytes and some architectures require 8-byte fetches to be fetched on 8-byte boundaries
(address divisible by 8 with no remainder).

Just a bit of parlor trickery.

At 09:52 AM 6/28/2006, you wrote:

>I saw some code in ACE:
>
>class ACE_Export ACE_U_LongLong
>{
>   ....
>   ....
>
>union
>      {
>        struct
>          {
>#     if defined (ACE_BIG_ENDIAN)
>            /// High 32 bits.
>            ACE_UINT32 hi_;
>
>            /// Low 32 bits.
>            ACE_UINT32 lo_;
>#     else
>            /// Low 32 bits.
>            ACE_UINT32 lo_;
>
>            /// High 32 bits.
>            ACE_UINT32 hi_;
>#     endif /* ! ACE_BIG_ENDIAN */
>
>          } data_;
>
>        /// To ensure alignment on 8-byte boundary.
>        /**
>         * @note "double" isn't usually usable with
>         *       ACE_LACKS_FLOATING_POINT, but this seems OK.
>         */
>        double for_alignment_;
>      };
>   ....
>};
>
>I don't understand why for_alignment_ can ensure aligment on 8-byte 
>boundary. Anyone can tell me?
>
>Thanks!
>
>ChinaGirl from Canada
>
>
>
>
>
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>
>
>
>-- 
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.1.394 / Virus Database: 268.9.5/377 - Release Date: 6/27/2006


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.394 / Virus Database: 268.9.5/377 - Release Date: 6/27/2006





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/