?
Solved

What 's different between two type aligns...

Posted on 2004-08-11
3
Medium Priority
?
217 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 80 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

Industry Leaders: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

649 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