Date: Tue, 12 Nov 1996 08:29:58 +0200 (IST) From: Eli Zaretskii To: "Brennan The Rev. Bas Underwood" Cc: djgpp AT delorie DOT com Subject: Re: ASM - Accessing structures In-Reply-To: <56889l$ib8@mack.rt66.com> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On 11 Nov 1996, Brennan The Rev. Bas Underwood wrote: > Since a struct is just a pile of memory, you need to know the location > of the beginning of the struct and the offset of the element you want. > The difficulty of this goes up (slightly) since gcc likes to pad structures, > so you can't just count bytes (unless you __attribute__((packed)) everything, > which is going to slow down your accesses, which asm won't compensate > for, so don't do that.) > > In C you can get the address of a struct element via &structname.element. > You can get the offset in bytes via > ((int)&structname.element - (int)&structname) There's no need to go to these lengths to compute offsets of struct fields. Just use the `offsetof' macro; it's ANSI C.