Solved

What 's different between two type aligns...

Posted on 2004-08-11
3
207 Views
Last Modified: 2010-04-15
Hi,Experts:
I use MSCV 6.0.
(1)
union Student{
   struct field
   {
      char sex;
      unsigned int age;
      double average;      
   };
   double align;
};
(2)
#pragma pack(push,8)      
struct Student
{
      char sex;
      unsigned int age;
      double average;      
};
#pragma pack(pop)      
(1) and (2) are  aligned on an 8-byte boundary.
Is there any different between them???
Thanks!
0
Comment
Question by:TKD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
aib_42 earned 20 total points
ID: 11788543
As it is, no.
However, the former may have a different alignment on a different platform/implementation.

Try adding a variable of type "__m128i" or "__m128d" or two into the struct. That should pull the alignment up to 16 bytes on a standard MSVC6 configuration.

Then compare the pragma'ed and the normal versions, you should see different alignments, as well as the fact that aligned SSE instructions would not work on the pragma'ed one.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question