www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/18/14:46:04

Date: Sun, 18 Aug 1996 12:40:37 -0600 (MDT)
From: The Lost Wizard of Absolutely Nothing <astlew00 AT Marcello DOT Augustana DOT AB DOT CA>
To: djgpp AT delorie DOT com
Subject: Re: What am i doing wrong?
In-Reply-To: <199608181702.AA28727@mail.umu.se>
Message-ID: <Pine.LNX.3.91.960818123904.6725B-100000@Marcello.Augustana.AB.CA>
MIME-Version: 1.0

On Sun, 18 Aug 1996, Andreas Vernersson wrote:

> Could anyone explain this?
> 
> typedef struct a
> {	unsigned int q2 __attribute__((packed));
> 	unsigned char qq __attribute__((packed));
> } b;
> 
> typedef struct a2
> {	
> 	unsigned int q2;
> 	unsigned char qq;
> } b2;
> 
> 
> void main()
> {
> 	printf("size: %d\n",(int)sizeof(b));  // 5 ???
> 	printf("size: %d\n",(int)sizeof(b2));  // 8  ???
> }
> 
> 
> ----
> I only wants the datastructure to be 2+1=3 bytes... 
> 

In DJGPP, an int is 32 bits which is four bytes. If you want a 16 bit 
integer, I suggest using `short' instead of `int'.

- Raw text -


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