cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/24/04:20:19

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help: My structure members aren't getting the right offsets!
Date: Mon, 24 Feb 1997 00:19:22 -0800
Organization: Alcyone Systems
Lines: 22
Message-ID: <33114F0A.2E800353@alcyone.com>
References: <3310E089 DOT 78F9 AT osha DOT igs DOT net>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Delong wrote:

> I even made code that added up the 'sizeof' each element and got 512
> bytes, please let me know if you know whats goind wrong here (since all
> data after VBEVersion_Major is getting screwed, but before that it
> works).

The problem is that you're assuming that all of the structure members are
packed perfectly, and you can't make this assumption with ANSI C (or draft
standard C++).  The compiler may add padding as it sees fit, to optimize
(or even allow!) more efficient references to the members.

What you're looking for is the packed attribute; check the info pages.
Note that this is, by its very nature, nonstandard.

-- 
       Erik Max Francis, &tSftDotIotE / email:  max AT alcyone DOT com
                     Alcyone Systems /    web:  http://www.alcyone.com/max/
San Jose, California, United States /    icbm:  37 20 07 N  121 53 38 W
                                   \
              "I am become death, / destroyer of worlds."
                                 / J. Robert Oppenheimer (quoting legend)

- Raw text -


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