delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/07/20:08:43

From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why does sizeof give me...
Date: 7 Aug 1997 07:02:47 GMT
Organization: The National Capital FreeNet
Lines: 21
Message-ID: <5sbrun$k8i@freenet-news.carleton.ca>
References: <33E957BE DOT 7216 AT geocities DOT com>
Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
NNTP-Posting-Host: freenet3.carleton.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

spiritseeker (spiritseeker AT geocities DOT com) writes:
> Hello, hello!
> 
> 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.

Two things: firstly, gcc is 32 bit and treats int as long, not short. Make
your app use short and long explicitly. Use short where the 16 bit app
used int in the structs. Second, gcc pads structs. Read the info on
__attribute__ ((packed)) and use it on the struct.
--
    .*.  Where feelings are concerned, answers are rarely simple [GeneDeWeese]
 -()  <  When I go to the theater, I always go straight to the "bag and mix"
    `*'  bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh

- Raw text -


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