Solved

What 's different between two type aligns...

Posted on 2004-08-11
3
202 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
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

Suggested Solutions

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

730 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