From: Brett Leslie Porter Message-Id: <199708070420.OAA16036@rabble.uow.edu.au> Subject: Re: Why does sizeof give me... To: spiritseeker AT geocities DOT com Date: Thu, 7 Aug 1997 14:20:22 +1000 (EST) Cc: djgpp AT delorie DOT com (DJGPP) In-Reply-To: <33E957BE.7216@geocities.com> from spiritseeker at "Aug 6, 97 10:06:06 pm" MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk > Hello, hello! Hello, 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! > Yes, 32-bit OS pads out structures, I think to dword boundary. Someone else can probably help you more here, as I'm am not entirely certain how it works, as I am not converting any 16 to 32 bit programs (yet!) You can probably set a compiler switch to turn off alignment, I'm not sure. How I would do it is to write a small program (or an extra function into your existing program) that reads the old files and writes the new. This would be done by reading _each field_ one at a time (not structure, field), place these values into a structure and write the structure using sizeof(), and repeat for all structures in file. You'd still have to watch that your original structures weren't padded in some way either though. Another thing that could be wrong is if your structure declared an 'int' type. In 16-bit Borland an int is equivalent to a short (16-bit signed integer), whereas 32-bit Borland and DJGPP both define an int as a long (32-bit signed integer). This will dramatically increase the size of your structure! Hope this is of some help, Brett