delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1996/12/20/12:07:58

From: paag AT tid DOT es ("Pedro A. Aranda Guti\irrez")
Subject: to pack or not to pack :=)
20 Dec 1996 12:07:58 -0800 :
Sender: daemon AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <32BA7571.69EE.cygnus.gnu-win32@tid.es>
Mime-Version: 1.0
X-Mailer: Mozilla 3.0 (Win95; I)
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

beta 17.1 still shows the same behaviour when it
finds chars in structures: it aligns the structure
to the next short boundary:

You still need the __attribute__((packed))

----------------------------------------------------

#include <stdio.h>
#include <stddef.h>

typedef struct {
  char ch;
  short sh;
  int   i;
  long  l;
} /* __attribute__((packed)) */ test;

int main(int argc,char **argv)
{
  printf("ch @ %d\n"
	 "sh @ %d\n"
	 "i  @ %d\n"
	 "l  @ %d\n",
	 offsetof(test,ch),
	 offsetof(test,sh),
	 offsetof(test,i),
	 offsetof(test,l));
}

-------------------------------------

ch @ 0
sh @ 2
i  @ 4
l  @ 8

-- 

     +--------------------------------------------------------+
     |  ####   Pedro Andres Aranda Gutierrez                  |
     |  ####                                                  |
     |  ####   Telefonica I+D;  Network Interconnection Div.  |
     |  ====   C./ Emilio Vargas, 6    E-28043 Madrid, Spain  |
     |  ====   e-mail : paag AT tid DOT es                           |
     |  ====   Tlf 34-1-337 47 02      FAX 34-1-337 45 02     |
     +--------------------------------------------------------+
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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