www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/19/08:30:16

Xref: news2.mv.net comp.os.msdos.djgpp:7623
From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What am i doing wrong?
Date: Sun, 18 Aug 1996 21:53:53 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 27
Message-ID: <3217F361.3C2@cs.com>
References: <199608181702 DOT AA28727 AT mail DOT umu DOT se>
NNTP-Posting-Host: ppp222.cs.com
Mime-Version: 1.0
To: Andreas Vernersson <hubble AT hem DOT passagen DOT se>
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Andreas Vernersson wrote:
> 
> Could anyone explain this?[snip]
> I only wants the datastructure to be 2+1=3 bytes...

DJGPP is a 32-bit compiler, which means it uses 32-bit ints.  So your 
structure (packed) is 4 bytes for the int plus 1 byte for the char = 5 
bytes.  Unpacked, the structure is padded to a multiple of 4, for a total 
of 8 bytes.

If you want the struct to be 3 bytes, simply use a short instead of an 
int.

Before you complain, the ANSI spec only says that 
sizeof(short)<=sizeof(int)<=sizeof(long).  Beyond that it's up to the 
compiler.  It's bad programming to depend on an int being any particular 
size.

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W+>++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


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