Re: gcc structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks, Jonathan, for your patience, and detailed answer.
I'll need to take some time to digest he wikipedia article.

I was thinking of structure instances, not definitions, when questioning
their positioning and padding.

I can see now that an instance of a structure of 9 ints followed by 8
doubles
would need to be positioned carefully to avoid that dreaded hole.

Thanks, but I may need to come back to you after studying that article.

JJ


On 8 September 2013 15:33, Jonathan Wakely-4 [via gcc] <
ml-node+s1065356n966628h59@xxxxxxxxxxxxx> wrote:

> On 8 September 2013 14:42, JimJoyce wrote:
> >
> > My question  'Are Structures doublewoord aligned?' was not about the
> second
> > half of the structure, but the beginning: an array of 9 ints.
> > It appears, having decided to place them on a doubleword boundary, it
> then
> > had to pad after the 9 ints to get back to an 8-byte boundary.
>
> Yes, there's a "hole" in the middle of the struct.
>
> > Was it pure mischance that the structure happened to start on a
> doubleword
> > that the extra int was needed. Had it started 4 bytes later, there would
> be
> > no padding?
>
> If you think about it that question doesn't make sense. The layout of
> a struct is always the same, irrespective of where an particular
> instance of that struct happens to be positioned in memory.  A
> struct's definition does not "start" anywhere in memory, only an
> instance of the struct has an address.
>
> > Or do structures always start on a doubleword?
>
> It depends on the types in the struct and the ABI of the target platform.
>
> There's plenty of information about this on the web, e.g.
>
> http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
> http://gcc.1065356.n5.nabble.com/gcc-structures-tp966595p966628.html
>  To unsubscribe from gcc structures, click here<http://gcc.1065356.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=966595&code=amltQGppbWpveWNlLmNvLnVrfDk2NjU5NXwtOTM4MDcwNDA4>
> .
> NAML<http://gcc.1065356.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 


JimJoyce
T: 0(044) 1280 813 899
E: jim@xxxxxxxxxxxxxx




--
View this message in context: http://gcc.1065356.n5.nabble.com/gcc-structures-tp966595p966657.html
Sent from the gcc - Help mailing list archive at Nabble.com.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux