delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/10/07:12:38

Newsgroups: comp.os.msdos.djgpp
Date: Wed, 6 Aug 1997 21:44:58 -0400
From: Insomnia <insomnia AT degobah DOT core DOT binghamton DOT edu>
Subject: Re: Why does sizeof give me...
In-Reply-To: <33E957BE.7216@geocities.com>
Message-ID: <Pine.SUN.3.93.970806213245.6848B-100000@degobah>
References: <33E957BE DOT 7216 AT geocities DOT com>
MIME-Version: 1.0
NNTP-Posting-Host: degobah.core.binghamton.edu
Organization: Binghamton University
Lines: 29
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 6 Aug 1997, spiritseeker wrote:

> I'm converting some code from my old 16 bit c programs to
> 32 bit .. suddenly sizeof gives me values that are many bytes
> larger than my old structures! This means whenever i want to fread 
> and fwrite files the structures get's messed up! 
> 
> I compiled the same .c file in borland. and there was a 300 byte
> difference beetwen the sizeof from bc and the one from djgpp.
> 
	At least part of your problem is most likely due to gcc's behavior
of 32-bit alligning fields in a structure.  This makes the structure
significantly faster, but the storage of the structure is bit different
than with Borland.
	To make it store elements more like you would expect, try
defining your structures with the attribute packed on each element in
the structure, ie: 
  struct mystruct {
    char element1 __attribute__ ((packed));
    int  element2 __attribute__ ((packed));
    .....
    };
	Hope this helps.  Corrections/constructive criticism welcome, as
are flames (I like seeing examples of people more pathetic than myself).

					--Insomnia

						--Sleep is for the weak!

- Raw text -


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