www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/12/01:40:12

Date: Tue, 12 Nov 1996 08:29:58 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Brennan The Rev. Bas Underwood" <brennan AT mack DOT rt66 DOT com>
Cc: djgpp AT delorie DOT com
Subject: Re: ASM - Accessing structures
In-Reply-To: <56889l$ib8@mack.rt66.com>
Message-Id: <Pine.SUN.3.91.961112082746.1964E-100000@is>
Mime-Version: 1.0

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. 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019