Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Aug 2002 19:09:16 -0700 
From:      "Balaji, Pavan" <pavan.balaji@intel.com>
To:        "'freebsd-questions@freebsd.org'" <freebsd-questions@freebsd.org>
Subject:   GCC versions!!!
Message-ID:  <3D386AED1B47D411A94300508B11F18704AD6999@fmsmsx116.fm.intel.com>

next in thread | raw e-mail | index | archive | help

Consider the following program:

test.c
----

#include <stdio.h>

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D386AED1B47D411A94300508B11F18704AD6999>