473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ALIGNMENT REVISITED 2

2)
struct B
{
int i;
short int si;
char c;
char d;
int j;
};


32 bit machine
--------------
1st block: i+pad = 4 bytes
2rd block: s1+pad = 4 bytes
3rd block" c+pad = 4 bytes
4th block: d+ pad = 4 bytes
5th block: j+pad = 4 bytes
---------------------------------------
TOTAL: 20 bytes
64 bit Machine
----------------
1st block: i + pad = 8 byte
2nd block: si + pad = 8 byte
3rd block: c + pad = 8 byte
4ht block: d + pad = 8 byte
5ht block: j + pad = 8 byte
---------------------------------
TOTAL: = 40 bytes

Why would it be differnt from the previous example?
would explain how to use sizeof to determine that as well?
what is POD and ALIGNED ADDRESS?


what is POD?
Thanks

Jul 22 '05 #1
7 1139
puzzlecracker wrote:
[...]
what is POD?


Try to learn to use groups.google.com to look up answers that
have already been given multiple times.
Jul 22 '05 #2
The following article should help:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Automate sequence diagram generation

Jul 22 '05 #3
"EventHelix.com" <ev********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
The following article should help:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm


Interesting. A dumb question: is there anything in standards that prohibits
compiler from rearranging the order of variables declared in a struct or
class? I have worked on compilers that rearranged variables to avoid padding
(old S/360). It wouldn't seem prudent, but perhaps there are compiler
switches for this, or not.
--
Gary
Jul 22 '05 #4
Gary Labowitz wrote:
"EventHelix.com" <ev********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
The following article should help:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Interesting. A dumb question: is there anything in standards that prohibits
compiler from rearranging the order of variables declared in a struct or
class? I have worked on compilers that rearranged variables to avoid padding
(old S/360). It wouldn't seem prudent, but perhaps there are compiler
switches for this, or not.


Yes, there is. 9.2/12: "Nonstatic data members of a (non-union) class
declared without an intervening access-specifier are allocated so that
later members have higher addresses within a class object."

V
Jul 22 '05 #5
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Rp*******************@newsread1.mlpsca01.us.t o.verio.net...
Gary Labowitz wrote:
"EventHelix.com" <ev********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
The following article should help:

http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Interesting. A dumb question: is there anything in standards that prohibits compiler from rearranging the order of variables declared in a struct or
class? I have worked on compilers that rearranged variables to avoid padding (old S/360). It wouldn't seem prudent, but perhaps there are compiler
switches for this, or not.


Yes, there is. 9.2/12: "Nonstatic data members of a (non-union) class
declared without an intervening access-specifier are allocated so that
later members have higher addresses within a class object."


Thank you. Then &b-&a makes sense for b declared after a. And sizeof(a)
would equal (&b-&a) if no padding were added?
--
Gary
Jul 22 '05 #6
Gary Labowitz wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Rp*******************@newsread1.mlpsca01.us.t o.verio.net...
Gary Labowitz wrote:
[..] A dumb question: is there anything in standards that


prohibits
compiler from rearranging the order of variables declared in a struct or
class? I have worked on compilers that rearranged variables to avoid
padding
(old S/360). It wouldn't seem prudent, but perhaps there are compiler
switches for this, or not.


Yes, there is. 9.2/12: "Nonstatic data members of a (non-union) class
declared without an intervening access-specifier are allocated so that
later members have higher addresses within a class object."

Thank you. Then &b-&a makes sense for b declared after a. And sizeof(a)
would equal (&b-&a) if no padding were added?


I don't see why not. Keep in mind that both 'a' and 'b' have to be in the
same access "section". If they are in different sections or if they have
the same access but there is another section between them, the &b-&a rule
doesn't apply any more.

V
Jul 22 '05 #7
I haven't come across any compilers that reorder the member
variables of a structure.

However, most compilers do have options to choose between
efficiency and memory requirement. For example, if accessing
a 32 integer is efficient at 4 byte boundaries, the default
option would be to align it that way. The compiler may let to align
it at (say) a 1 byte boundary.

This is applicable only on platforms that will allow misaligned
transfers.

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Automate sequence diagram generation

Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shashi | last post by:
Can somebody explain how the byte alignment for structures work, taking the following example and considering: byte of 1 Byte word of 2 Bytes dword of 4 Bytes typedef struct { byte a; word...
10
by: j0mbolar | last post by:
for any pointer to T, does a pointer to T have different or can have different alignment requirement than a pointer to pointer to T? if so, where is the exact wording in the standard that would...
67
by: S.Tobias | last post by:
I would like to check if I understand the following excerpt correctly: 6.2.5#26 (Types): All pointers to structure types shall have the same representation and alignment requirements as each...
17
by: puzzlecracker | last post by:
> 2) >>struct B >>{ >> int i; >>short int si; >> char c; >> char d; >> int j; >>};
7
by: Earl | last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid (VS2003)? I've tried Ken's workaround...
13
by: aegis | last post by:
The following was mentioned by Eric Sosman from http://groups.google.com/group/comp.lang.c/msg/b696b28f59b9dac4?dmode=source "The alignment requirement for any type T must be a divisor of...
12
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: #include <stdlib.h> #define MAGIC_NUMBER 64 void *my_malloc (size_t n) { char *result = malloc (n + MAGIC_NUMBER);
10
by: haomiao | last post by:
I want to implement a common list that can cantain any type of data, so I declare the list as (briefly) --------------------------------------- struct list { int data_size; int node_num;...
2
by: somenath | last post by:
Hi All, I have one question regarding the alignment of pointer returned by malloc. In K&R2 page number 186 one union is used to enforce the alignment as mentioned bellow. typedef long...
2
by: uamusa | last post by:
I am Dynamically generating a proposal(report) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.