From owner-freebsd-questions Sun Aug 4 19: 9:22 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6C06F37B400 for ; Sun, 4 Aug 2002 19:09:19 -0700 (PDT) Received: from mail1.hd.intel.com (hdfdns01.hd.intel.com [192.52.58.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id B580E43E5E for ; Sun, 4 Aug 2002 19:09:18 -0700 (PDT) (envelope-from pavan.balaji@intel.com) Received: from fmsmsxvs040.fm.intel.com (fmsmsxvs040.fm.intel.com [132.233.42.124]) by mail1.hd.intel.com (8.11.6/8.11.6/d: solo.mc,v 1.42 2002/05/23 22:21:11 root Exp $) with SMTP id g7529HP15827 for ; Mon, 5 Aug 2002 02:09:17 GMT Received: from fmsmsx28.fm.intel.com ([132.233.42.28]) by fmsmsxvs040.fm.intel.com (NAVGW 2.5.2.11) with SMTP id M2002080419082327645 for ; Sun, 04 Aug 2002 19:08:23 -0700 Received: by fmsmsx28.fm.intel.com with Internet Mail Service (5.5.2653.19) id ; Sun, 4 Aug 2002 19:09:17 -0700 Message-ID: <3D386AED1B47D411A94300508B11F18704AD6999@fmsmsx116.fm.intel.com> From: "Balaji, Pavan" To: "'freebsd-questions@freebsd.org'" Subject: GCC versions!!! Date: Sun, 4 Aug 2002 19:09:16 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Consider the following program: test.c ---- #include struct { char x1; char x2; short x3; short x4; } a; int main() { int *k; a.x1 = 1; a.x2 = 0; a.x3 = 0; a.x4 = 0; k = &a; printf ("%d ", *k); a.x1 = 0; a.x2 = 1; a.x3 = 0; a.x4 = 0; k = &a; printf ("%d ", *k); a.x1 = 0; a.x2 = 0; a.x3 = 1; a.x4 = 0; k = &a; printf ("%d ", *k); a.x1 = 0; a.x2 = 0; a.x3 = 0; a.x4 = 1; k = &a; printf ("%d ", *k); return 0; } --- I ran this program on FreeBSD (GCC version 2.95.3) and the output for this program was 1 256 65536 0 I reran it on Linux (GCC version 3.0.something) and the output was: 16777216 65536 1 0 (as expected). After a little poking around, I could figure out that the memory for the structure was allocated in a way that for every word boundary, the bytes allocation is in the reverse order. For example, if I have 4 characters in a structure a, b, c and d, the memory for d is allocated first, then c, then b and finally a. Is this something to do with gcc or with freebsd? Any ideas? Pavan Balaji, Intel Corporation Email: pavan.balaji@intel.com "Only the Paranoid Survive" -- Andy Grove To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message