473,804 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

structure padding

Hi all,
I understand that some compilers pad some bytes to the
aggregate data types in order to access the members of the aggregate
data types(i.e. structure) fast. This depends on the architectures.
Some architectures cannot access the data which will be stored on the
odd addresses or they may find difficult to access it. This is the
reason for padding extra bytes.

Now consider the following structure:

struct {
int i; // 4 bytes
char c; // 1 byte
char b; // 1 byte
}a;

Now consider the memory representation for this structure:

----------------------------- Memory locations
i 0
-----------------------------
i 1
-----------------------------
i 2
------------------------------
i 3
-------------------------------
c 4
--------------------------------
b 5
--------------------------------
padding 6
---------------------------------
padding 7
---------------------------------

The size of this strucutre will be 8bytes after padding.
The first 4 memory locations(0 to 3) are allocated for int i;
The next byte(4) is allocated for char c;
the next byte(5) is allocated for char b;

Now my doubt is , does not the processor find it difficult to access
the value of the variable which is stored in odd memory location(ie.
5)? can anyone elaborate on this?

Regards

Feb 2 '06
28 20806

"CBFalconer " <cb********@yah oo.com> wrote in message
news:43******** *******@yahoo.c om...
Rod Pemberton wrote:

... snip ...

C) It amazes me that there are so many people _here_ who incessantly
whine about things that are _beyond_ their control, like: judgemental
off-topic posts, top posting, cutting reply signatures. The
'perceived constraints' that you experience are _you're_ problem.
Not mine. Honestly, whining about these things reminds me of the
bickering of immature little children. Keep it to yourself and learn
to deal with it.


However the whining bickering immature children often grow up into
useful adults, provided they are corrected when whining, bickering,
or otherwise acting immature. Here we can only identify the
children by their immature actions, such as top-posting, omitting
context, chopping off attributions, failure to snip.


They aren't the ones whining, bickering, and acting immature... You are.
Rod Pemberton
Feb 3 '06 #21

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"Rod Pemberton" <do*******@bitb ucket.cmm> writes:
[snip]
C) It amazes me that there are so many people _here_ who incessantly whine about things that are _beyond_ their control, like: judgemental off-topic posts, top posting, cutting reply signatures. The 'perceived constraints' that you experience are _you're_ problem. Not mine. Honestly, whining
about these things reminds me of the bickering of immature little children. Keep it to yourself and learn to deal with it.
Um, no.


Um, yes.
There are very good reasons why we try to encourage people to follow
some simple posting guidelines here. Jack Klein did an excellent job
of explaining those reasons.


I don't need to read any of his reasons to know they are totally irrevelant.
You may agree with his statements. But, it doesn't change the fact that you
need to learn accept things the way they are.
Rod Pemberton



Feb 3 '06 #22
"Rod Pemberton" <do*******@bitb ucket.cmm> writes:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"Rod Pemberton" <do*******@bitb ucket.cmm> writes:
[snip]
> C) It amazes me that there are so many people _here_ who
> incessantly whine about things that are _beyond_ their control,
> like: judgemental off-topic posts, top posting, cutting reply
> signatures. The 'perceived constraints' that you experience are
> _you're_ problem. Not mine. Honestly, whining about these
> things reminds me of the bickering of immature little children.
> Keep it to yourself and learn to deal with it.
Um, no.


Um, yes.
There are very good reasons why we try to encourage people to follow
some simple posting guidelines here. Jack Klein did an excellent job
of explaining those reasons.


I don't need to read any of his reasons to know they are totally
irrevelant.


Yes, you do.
You may agree with his statements. But, it doesn't change the fact that you
need to learn accept things the way they are.


I strongly suggest you read Jack's article anyway. You might or might
not agree, but what he wrote happens to represent the consensus of the
regulars of this newsgroup (trolls excluded). You are, of course,
free to jam your fists into your ears and shout "LALALALALA " until the
bad people stop talking to you.

You make an interesting point about accepting things the way they are.
The same logic implies we should accept spam.

Let me explain to you the way things are. This newsgroup is about
standard C. If you're unwilling to accept that, you will be unable to
participate. Many of the people who happen to know a lot about the
topic will killfile you. I'm sure some of them have already.

If people who know more about this than you do tell you that you're
wrong, you should consider listening to them rather than whining.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 4 '06 #23
On Fri, 03 Feb 2006 23:39:52 GMT, in comp.lang.c , "Rod Pemberton"
<do*******@bitb ucket.cmm> wrote:

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******* *****@nuthaus.m ib.org...
There are very good reasons why we try to encourage people to follow
some simple posting guidelines here. Jack Klein did an excellent job
of explaining those reasons.


I don't need to read any of his reasons to know they are totally irrevelant.


I see. You just don't care. Nice.
You may agree with his statements. But, it doesn't change the fact that you
need to learn accept things the way they are.


There's an alternative - you, yes, you, need to accept things the way
they are in CLC.
Can't handle that? Don't like it? Tough.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 4 '06 #24
Rod Pemberton wrote:

I don't need to read any of his reasons to know they are totally
irrevelant. You may agree with his statements. But, it doesn't
change the fact that you need to learn accept things the way they are.


*plonk*
Brian
Feb 4 '06 #25

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"Rod Pemberton" <do*******@bitb ucket.cmm> writes:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"Rod Pemberton" <do*******@bitb ucket.cmm> writes:
[snip]
> C) It amazes me that there are so many people _here_ who
> incessantly whine about things that are _beyond_ their control,
> like: judgemental off-topic posts, top posting, cutting reply
> signatures. The 'perceived constraints' that you experience are
> _you're_ problem. Not mine. Honestly, whining about these
> things reminds me of the bickering of immature little children.
> Keep it to yourself and learn to deal with it.

Um, no.
Um, yes.
There are very good reasons why we try to encourage people to follow
some simple posting guidelines here. Jack Klein did an excellent job
of explaining those reasons.


I don't need to read any of his reasons to know they are totally
irrevelant.


Yes, you do.
You may agree with his statements. But, it doesn't change the fact that you need to learn accept things the way they are.


I strongly suggest you read Jack's article anyway. You might or might
not agree, but what he wrote happens to represent the consensus of the
regulars of this newsgroup (trolls excluded). You are, of course,
free to jam your fists into your ears and shout "LALALALALA " until the
bad people stop talking to you.
You make an interesting point about accepting things the way they are.
The same logic implies we should accept spam.

Let me explain to you the way things are. This newsgroup is about
standard C. If you're unwilling to accept that, you will be unable to
participate. Many of the people who happen to know a lot about the
topic will killfile you. I'm sure some of them have already.


This is comp.lang.c not comp.lang.c.iso or comp.lang.c.ans i or
comp.lang.c.knr ... The point which you seem unable to comprehend is that
_you're_ whining. And, it's irritating people. I know what my IQ is. I
know how in depth my knowledge of C is. And, From my conversations with you
so far, you don't come close to either.
If people who know more about this than you do tell you that you're
wrong, you should consider listening to them rather than whining.


I'm not the one whining. You are. Incessantly, about top-posting,
inlining, google.. Out of the last thirty posts of yours, only one(1) has
contributed anything meaningful to any thread. Only one(1) hasn't been a
complaint. You may think of yourself as a regular, but given your posting
history you are the definition of a _TROLL_. I sincerely hope you aren't
referring to yourself when you mention 'people who know more about this than
you'...

Rod Pemberton

Feb 4 '06 #26
Rod Pemberton wrote:
"Keith Thompson" <ks***@mib.or g> wrote in message
<snip>
Let me explain to you the way things are. This newsgroup is about
standard C. If you're unwilling to accept that, you will be unable to
participate. Many of the people who happen to know a lot about the
topic will killfile you. I'm sure some of them have already.


This is comp.lang.c not comp.lang.c.iso or comp.lang.c.ans i or
comp.lang.c.knr ...


Yes, it's comp.lang.c, not
comp.lang.c.win dows.and.posix. and.vxworks.and .dos.and.aix.an d.everything.el se.under.the.su n
The point which you seem unable to comprehend is that
_you're_ whining. And, it's irritating people. I know what my IQ is. I
know how in depth my knowledge of C is. And, From my conversations with you
so far, you don't come close to either.


My impression having seen Keith's posts since I've been on the group is
that he is highly knowledgeable and an intelligent chap.

You come across as the person whining about the group not being what you
want it to be.
If people who know more about this than you do tell you that you're
wrong, you should consider listening to them rather than whining.


I'm not the one whining. You are. Incessantly, about top-posting,
inlining, google.. Out of the last thirty posts of yours, only one(1) has
contributed anything meaningful to any thread. Only one(1) hasn't been a
complaint. You may think of yourself as a regular, but given your posting
history you are the definition of a _TROLL_. I sincerely hope you aren't
referring to yourself when you mention 'people who know more about this than
you'...


I believe the people Keith is referring to include members of the
standard committee, authors of successful C implementations (or parts
their of) and authors of successful books on C. Keith and the others
that correct peoples posting style also provide a lot of useful content
(I attempt to fall in to that category as well).

If you don't like the attitude of the regulars or the limits on what the
regulars consider to be topical, feel free to find yourself another group.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Feb 4 '06 #27
On Sat, 04 Feb 2006 04:39:49 GMT, in comp.lang.c , "Rod Pemberton"
<do*******@bitb ucket.cmm> wrote:
This is comp.lang.c not comp.lang.c.iso or comp.lang.c.ans i or
comp.lang.c.kn r...
Correct. and hte topic of comp.lang.c is use of the C Language as
defined by ISO.
The point which you seem unable to comprehend is that
_you're_ whining. And, it's irritating people.
Wrong on both counts.

The point *you* seem unable to comprehend is that the topic of this
group is not Windows, nor unix, nor databases, nor TCPIP.

It doesn't matter that you can link your C code with libraries to
access these things, you can similarly do it from Fortran, Basic,
perl, python, and for all I know Haskell. These services are *not part
of C* and are therefore offtopic.
I know what my IQ is. I
know how in depth my knowledge of C is. And, From my conversations with you
so far, you don't come close to either.


I agree. It will be many decades before you can climb up to Keith's
level on either front, and meantime you'll need to learn some
humility.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 4 '06 #28
On 2006-02-04, Mark McIntyre <ma**********@s pamcop.net> wrote:
On Sat, 04 Feb 2006 04:39:49 GMT, in comp.lang.c , "Rod Pemberton"
<do*******@bitb ucket.cmm> wrote:
This is comp.lang.c not comp.lang.c.iso or comp.lang.c.ans i or
comp.lang.c.k nr...


Correct. and hte topic of comp.lang.c is use of the C Language as
defined by ISO.


Or as defined by ANSI in the 80s, or as defined by K&R in the 70s.

Not, of course, as defined by Microsoft, or Borland, or GNU.
Feb 5 '06 #29

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

Similar topics

13
3896
by: Amarendra | last post by:
Folks, This structure padding issue is bothering me now, could not locate a satisfactory answer on clc, so here it goes... I have a structure, given below: typedef struct { int flag; char keys; char padding;
2
1857
by: Sachin | last post by:
typdef struct { int i; char ch; }str; str str_var; char x, y; main() { //do nothing
15
2789
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
10
2315
by: ranjeet.gupta | last post by:
Dear All !! Before i qoute my querry, I will like to qoute my analysis and my Knowledge Struct a { int raw; char data; };
20
2325
by: Lalatendu Das | last post by:
hi let's say i have a structure struct test { int A; char B; int C; }; this above structure defination always going to take 16 byte in memeory in whatever manner we align the member variables while declaring a variable to it . because variable 'A' going to take 4 byte then four charachter of
28
3649
by: kyle york | last post by:
Greetings, Why does the C standard require the members of a structure not be re-ordered (6.2.5.20)? Padding is allowed, and platform dependent, which means one cannot rely on the exact layout anyway, so what's the point? Without this restriction the compiler could layout the structure in the most efficient way possible, for some definition of efficient. It would be easy enough to turn this reordering off with a compiler specific...
4
11214
by: junky_fellow | last post by:
Can somebody please tell me about the structure alignment rules ? What I found was that on my system (cygwin running on PC, size of int=4 sizeof long=4, size of long long = 8) the cygwin compiler put the padding after the last member of structure. For eg, struct test { int i; char c; /* no padding required between int and char */ /* 3 byte padding is inserted here, Why ? */
24
2131
by: karthikbalaguru | last post by:
Hi, I find that the structure padding is not being taken into account while using 'new' operator. Is there a way to enable it ? struct Dataunit { char dataid; int keyid;
10
3293
by: Rohit kumar Chandel | last post by:
Hi All, Please let me know how to find in a structure whether compiler has used padding or not. Regards Rohit
12
4808
by: Kislay | last post by:
case 1 : struct s { char c1; // 8 double d; // 8 int i1; // 4 char c2; // 4 int i2; // 4 };
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.