Related articles |
---|
help with the layout of structures in C/C++ muller@src.dec.com (1992-06-09) |
Newsgroups: | comp.lang.c,comp.lang.c++,comp.lang.modula3,comp.compilers |
From: | muller@src.dec.com (Eric Muller) |
Followup-To: | comp.lang.c |
Keywords: | C, storage |
Organization: | DEC Systems Research Center |
Date: | Tue, 9 Jun 1992 07:01:38 GMT |
[Moderator's note: This is one of the longest messages I've ever sent to
comp.compilers. Would people have preferred that I put it on the mail
and FTP servers so those who wanted to try it could pick it up? -John]
Hello,
We would like your help: could you please run the program below on as many
combinations of machine/C/C++ compiler you have access to ? It does not
matter if the compiler is ANSI-C or not, and the program should work on
16-bit, 32-bit and 64-bit machines.
Our goal is to find out how the various C/C++ compilers represent
structures, in particular bitfields. The file README contains a detailed
explanation of the problem we are trying to solve
When describing the combination(s) of machine/compiler you are Please be
as precise as possible about the hardware, operating system version, C/C++
compiler version as you can.
We will make all the results available, with the proper credits. If you
prefer to remain anonymous, please tell us.
Thanks very much for your help,
Eric Muller muller@src.dec.com
DEC Systems Research Center
130 Lytton Av.
Palo Alto, CA 94301
(415) 853 21 93 Fax: (415) 324 48 76
---- Cut Here and unpack ----
#!/bin/sh
# This is a shell archive (shar 3.32)
# made 06/09/1992 06:59 UTC by muller@procope.pa.dec.com
# Source directory /tmp_mnt/flimflam/r/dlusers5/muller/work/struct/test2
#
# existing files WILL be overwritten
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2691 -rw-r--r-- README
# 34762 -rw-r--r-- params.c
# 1484 -rw-r--r-- random.c
# 979 -rw-r--r-- Makefile
#
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= README ==============
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
XWe are working on a compiler for Modula-3. Because we want to make it
Xeasy to mix Modula-3 and other languages, for example C, we need to be
Xcompatible in a number of respects: calling sequences, representation
Xof basic types and so on. There is one area were we still have
Xproblems: the layout of structure declarations, in particular in the
Xpresence of bitfields. As you may know the ANSI C standard gives a
Xlot of freedom to the implementer, and this only recognizes the
Xvariety of existing "C" compilers. For example, the two structures:
X
X struct {int a; char b; signed int c: sizeof (char); }
X
X struct {int a; char b; char c; }
X
Xare not always equivalent.
X
XIn a previous posting to comp.compilers, we asked for an algorithm
Xthat could be parameterized to reflect what various machine/compiler
Xcombinations do. Although we got some interesting answers (thanks a
Xlot), none provided the algorithm we have been looking for. In fact,
Xmany people are not really aware of the problems. So we wrote a
Xsimple program to report the size of various structures, and sent it
Xto our friends. We were fortunate to get many answers (in fact, 43
Xmachine/compiler combinations), and we have designed an algorithm that
Xexplains all the results we have received. This first test program
Xwas just meant to give us an idea of what to expect from the various C
Xcompilers and it did not collect exhaustive data.
X
XWe think that our algorithm will cover a very large number of
Xmachines/combinations (in fact, it is a bit more parameterized than we
Xthink is needed, just to be on the safe side). Now, we would like to
Xconfirm or infirm that thesis, and the best way is to have the program
Xrun on as many machines/compilers as possible.
X
XWhy should you care ? The example above should be enough to tell you
Xthat bitfields are not really the most portable construct in C. You
Xcan avoid them, but you may as well know what works and what does not.
XAlso, this may explain why some third-party C (or non-C) compilers do
Xnot interoperate properly with the vendors C compilers (and libraries).
X
XWhen describing the combination(s) of machine/compiler you are trying,
Xplease be as precise as possible about the hardware, operating system
Xversion, C/C++ compiler version as you can. We are also interested in
Xany problem you may have compiling or running the programs.
X
XWe will make all the results available, with the proper credits. If
Xyou prefer to remain anonymous, please tell us.
X
XThanks very much for your help,
X
XEric Muller muller@src.dec.com
XDEC Systems Research Center
X130 Lytton Av.
XPalo Alto, CA 94301
X(415) 853 21 93 Fax: (415) 324 48 76
X
X
SHAR_EOF
$TOUCH -am 0608233992 README &&
chmod 0644 README ||
echo "restore of README failed"
set `wc -c README`;Wc_c=$1
if test "$Wc_c" != "2691"; then
echo original size 2691, current size $Wc_c
fi
# ============= params.c ==============
echo "x - extracting params.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > params.c &&
Xint a[100], s[100], p[100], start[100], stop[100], size, align;
Xchar *block;
Xint report_losses;
X
X#define MAX(a,b) ((a>b) ? a : b)
X#define roundup(x,y) (((x+y-1)/y)*y)
X#define rounddown(x,y) (((x)/y)*y)
X
X#define SZ(x) (sizeof(x) * BITS_PER_BYTE)
X#define AL(TYPE) \
X ((long)((char *)&((struct{char c; TYPE d;}*)0)->d \
X - (char *)0) * BITS_PER_BYTE)
X
Xint
X s_char, a_char,
X s_short, a_short,
X s_int, a_int,
X s_long, a_long,
X s_float, a_float,
X s_double, a_double;
X
Xint
X BITFIELD_UNITS_OVERLAP,
X BITFIELD_UNIT_SIZE,
X BITFIELD_UNIT_ALIGN,
X FIELD_PAD_BITFIELD,
X BITFIELD_PAD_FIELD,
X BITFIELD_SIZE_ALIGN [100],
X NUMBER_PAD_SIZES,
X PAD_SIZES [100],
X BITS_PER_BYTE;
X
Xtypedef struct {char a[0x01];} SC0x01;
Xtypedef struct {char a[0x02];} SC0x02;
Xtypedef struct {char a[0x03];} SC0x03;
Xtypedef struct {char a[0x04];} SC0x04;
Xtypedef struct {char a[0x05];} SC0x05;
Xtypedef struct {char a[0x06];} SC0x06;
Xtypedef struct {char a[0x07];} SC0x07;
Xtypedef struct {char a[0x08];} SC0x08;
Xtypedef struct {char a[0x09];} SC0x09;
Xtypedef struct {char a[0x0a];} SC0x0a;
Xtypedef struct {char a[0x0b];} SC0x0b;
Xtypedef struct {char a[0x0c];} SC0x0c;
Xtypedef struct {char a[0x0d];} SC0x0d;
Xtypedef struct {char a[0x0e];} SC0x0e;
Xtypedef struct {char a[0x0f];} SC0x0f;
Xtypedef struct {char a[0x10];} SC0x10;
Xtypedef struct {char a[0x11];} SC0x11;
Xtypedef struct {char a[0x12];} SC0x12;
Xtypedef struct {char a[0x13];} SC0x13;
Xtypedef struct {char a[0x14];} SC0x14;
Xtypedef struct {char a[0x15];} SC0x15;
Xtypedef struct {char a[0x16];} SC0x16;
Xtypedef struct {char a[0x17];} SC0x17;
Xtypedef struct {char a[0x18];} SC0x18;
Xtypedef struct {char a[0x19];} SC0x19;
Xtypedef struct {char a[0x1a];} SC0x1a;
Xtypedef struct {char a[0x1b];} SC0x1b;
Xtypedef struct {char a[0x1c];} SC0x1c;
Xtypedef struct {char a[0x1d];} SC0x1d;
Xtypedef struct {char a[0x1e];} SC0x1e;
Xtypedef struct {char a[0x1f];} SC0x1f;
Xtypedef struct {char a[0x20];} SC0x20;
X
Xtypedef struct {int a: 0x01;} S0x01; S0x01 v0x01;
Xtypedef struct {int a: 0x02;} S0x02; S0x02 v0x02;
Xtypedef struct {int a: 0x03;} S0x03; S0x03 v0x03;
Xtypedef struct {int a: 0x04;} S0x04; S0x04 v0x04;
Xtypedef struct {int a: 0x05;} S0x05; S0x05 v0x05;
Xtypedef struct {int a: 0x06;} S0x06; S0x06 v0x06;
Xtypedef struct {int a: 0x07;} S0x07; S0x07 v0x07;
Xtypedef struct {int a: 0x08;} S0x08; S0x08 v0x08;
Xtypedef struct {int a: 0x09;} S0x09; S0x09 v0x09;
Xtypedef struct {int a: 0x0a;} S0x0a; S0x0a v0x0a;
Xtypedef struct {int a: 0x0b;} S0x0b; S0x0b v0x0b;
Xtypedef struct {int a: 0x0c;} S0x0c; S0x0c v0x0c;
Xtypedef struct {int a: 0x0d;} S0x0d; S0x0d v0x0d;
Xtypedef struct {int a: 0x0e;} S0x0e; S0x0e v0x0e;
Xtypedef struct {int a: 0x0f;} S0x0f; S0x0f v0x0f;
Xtypedef struct {int a: 0x10;} S0x10; S0x10 v0x10;
Xtypedef struct {int a: 0x11;} S0x11; S0x11 v0x11;
Xtypedef struct {int a: 0x12;} S0x12; S0x12 v0x12;
Xtypedef struct {int a: 0x13;} S0x13; S0x13 v0x13;
Xtypedef struct {int a: 0x14;} S0x14; S0x14 v0x14;
Xtypedef struct {int a: 0x15;} S0x15; S0x15 v0x15;
Xtypedef struct {int a: 0x16;} S0x16; S0x16 v0x16;
Xtypedef struct {int a: 0x17;} S0x17; S0x17 v0x17;
Xtypedef struct {int a: 0x18;} S0x18; S0x18 v0x18;
Xtypedef struct {int a: 0x19;} S0x19; S0x19 v0x19;
Xtypedef struct {int a: 0x1a;} S0x1a; S0x1a v0x1a;
Xtypedef struct {int a: 0x1b;} S0x1b; S0x1b v0x1b;
Xtypedef struct {int a: 0x1c;} S0x1c; S0x1c v0x1c;
Xtypedef struct {int a: 0x1d;} S0x1d; S0x1d v0x1d;
Xtypedef struct {int a: 0x1e;} S0x1e; S0x1e v0x1e;
Xtypedef struct {int a: 0x1f;} S0x1f; S0x1f v0x1f;
Xtypedef struct {int a: 0x20;} S0x20; S0x20 v0x20;
X
Xtypedef struct {char a; int b: 0x19;} Sc0x19;
Xtypedef struct {char a; int b: 0x02;} Sc0x02;
Xtypedef struct {char a; int b: 0x20;} Sc0x20;
Xtypedef struct {char a; int b: 0x04;} Sc0x04;
Xtypedef struct {char a; int b: 0x05;} Sc0x05;
Xtypedef struct {char a; int b: 0x08;} Sc0x08;
Xtypedef struct {char a; int b: 0x09;} Sc0x09;
Xtypedef struct {char a; int b: 0x0c;} Sc0x0c;
Xtypedef struct {char a; int b: 0x10;} Sc0x10;
Xtypedef struct {char a; int b: 0x11;} Sc0x11;
Xtypedef struct {char a; int b: 0x14;} Sc0x14;
Xtypedef struct {char a; int b: 0x17;} Sc0x17;
Xtypedef struct {char a; int b: 0x18;} Sc0x18;
Xtypedef struct {char a; int b: 0x01;} Sc0x01;
XSc0x19 vc0x19;
XSc0x02 vc0x02;
XSc0x20 vc0x20;
XSc0x04 vc0x04;
XSc0x05 vc0x05;
XSc0x08 vc0x08;
XSc0x09 vc0x09;
XSc0x0c vc0x0c;
XSc0x10 vc0x10;
XSc0x11 vc0x11;
XSc0x14 vc0x14;
XSc0x17 vc0x17;
XSc0x18 vc0x18;
XSc0x01 vc0x01;
X
Xtypedef struct {short a; int b: 0x19;} Ss0x19;
Xtypedef struct {short a; int b: 0x02;} Ss0x02;
Xtypedef struct {short a; int b: 0x20;} Ss0x20;
Xtypedef struct {short a; int b: 0x04;} Ss0x04;
Xtypedef struct {short a; int b: 0x05;} Ss0x05;
Xtypedef struct {short a; int b: 0x08;} Ss0x08;
Xtypedef struct {short a; int b: 0x09;} Ss0x09;
Xtypedef struct {short a; int b: 0x0c;} Ss0x0c;
Xtypedef struct {short a; int b: 0x10;} Ss0x10;
Xtypedef struct {short a; int b: 0x11;} Ss0x11;
Xtypedef struct {short a; int b: 0x14;} Ss0x14;
Xtypedef struct {short a; int b: 0x17;} Ss0x17;
Xtypedef struct {short a; int b: 0x18;} Ss0x18;
Xtypedef struct {short a; int b: 0x01;} Ss0x01;
XSs0x19 vs0x19;
XSs0x02 vs0x02;
XSs0x20 vs0x20;
XSs0x04 vs0x04;
XSs0x05 vs0x05;
XSs0x08 vs0x08;
XSs0x09 vs0x09;
XSs0x0c vs0x0c;
XSs0x10 vs0x10;
XSs0x11 vs0x11;
XSs0x14 vs0x14;
XSs0x17 vs0x17;
XSs0x18 vs0x18;
XSs0x01 vs0x01;
X
Xtypedef struct {int a; int b: 0x19;} Si0x19;
Xtypedef struct {int a; int b: 0x02;} Si0x02;
Xtypedef struct {int a; int b: 0x20;} Si0x20;
Xtypedef struct {int a; int b: 0x04;} Si0x04;
Xtypedef struct {int a; int b: 0x05;} Si0x05;
Xtypedef struct {int a; int b: 0x08;} Si0x08;
Xtypedef struct {int a; int b: 0x09;} Si0x09;
Xtypedef struct {int a; int b: 0x0c;} Si0x0c;
Xtypedef struct {int a; int b: 0x10;} Si0x10;
Xtypedef struct {int a; int b: 0x11;} Si0x11;
Xtypedef struct {int a; int b: 0x14;} Si0x14;
Xtypedef struct {int a; int b: 0x17;} Si0x17;
Xtypedef struct {int a; int b: 0x18;} Si0x18;
Xtypedef struct {int a; int b: 0x01;} Si0x01;
XSi0x19 vi0x19;
XSi0x02 vi0x02;
XSi0x20 vi0x20;
XSi0x04 vi0x04;
XSi0x05 vi0x05;
XSi0x08 vi0x08;
XSi0x09 vi0x09;
XSi0x0c vi0x0c;
XSi0x10 vi0x10;
XSi0x11 vi0x11;
XSi0x14 vi0x14;
XSi0x17 vi0x17;
XSi0x18 vi0x18;
XSi0x01 vi0x01;
X
Xtypedef struct {long a; int b: 0x19;} Sl0x19;
Xtypedef struct {long a; int b: 0x02;} Sl0x02;
Xtypedef struct {long a; int b: 0x20;} Sl0x20;
Xtypedef struct {long a; int b: 0x04;} Sl0x04;
Xtypedef struct {long a; int b: 0x05;} Sl0x05;
Xtypedef struct {long a; int b: 0x08;} Sl0x08;
Xtypedef struct {long a; int b: 0x09;} Sl0x09;
Xtypedef struct {long a; int b: 0x0c;} Sl0x0c;
Xtypedef struct {long a; int b: 0x10;} Sl0x10;
Xtypedef struct {long a; int b: 0x11;} Sl0x11;
Xtypedef struct {long a; int b: 0x14;} Sl0x14;
Xtypedef struct {long a; int b: 0x17;} Sl0x17;
Xtypedef struct {long a; int b: 0x18;} Sl0x18;
Xtypedef struct {long a; int b: 0x01;} Sl0x01;
XSl0x19 vl0x19;
XSl0x02 vl0x02;
XSl0x20 vl0x20;
XSl0x04 vl0x04;
XSl0x05 vl0x05;
XSl0x08 vl0x08;
XSl0x09 vl0x09;
XSl0x0c vl0x0c;
XSl0x10 vl0x10;
XSl0x11 vl0x11;
XSl0x14 vl0x14;
XSl0x17 vl0x17;
XSl0x18 vl0x18;
XSl0x01 vl0x01;
X
Xtypedef struct {char a; int b: 0x19; char c;} Sc0x19c;
Xtypedef struct {char a; int b: 0x02; char c;} Sc0x02c;
Xtypedef struct {char a; int b: 0x20; char c;} Sc0x20c;
Xtypedef struct {char a; int b: 0x04; char c;} Sc0x04c;
Xtypedef struct {char a; int b: 0x05; char c;} Sc0x05c;
Xtypedef struct {char a; int b: 0x08; char c;} Sc0x08c;
Xtypedef struct {char a; int b: 0x09; char c;} Sc0x09c;
Xtypedef struct {char a; int b: 0x0c; char c;} Sc0x0cc;
Xtypedef struct {char a; int b: 0x10; char c;} Sc0x10c;
Xtypedef struct {char a; int b: 0x11; char c;} Sc0x11c;
Xtypedef struct {char a; int b: 0x14; char c;} Sc0x14c;
Xtypedef struct {char a; int b: 0x17; char c;} Sc0x17c;
Xtypedef struct {char a; int b: 0x18; char c;} Sc0x18c;
Xtypedef struct {char a; int b: 0x01; char c;} Sc0x01c;
XSc0x19c vc0x19c;
XSc0x02c vc0x02c;
XSc0x20c vc0x20c;
XSc0x04c vc0x04c;
XSc0x05c vc0x05c;
XSc0x08c vc0x08c;
XSc0x09c vc0x09c;
XSc0x0cc vc0x0cc;
XSc0x10c vc0x10c;
XSc0x11c vc0x11c;
XSc0x14c vc0x14c;
XSc0x17c vc0x17c;
XSc0x18c vc0x18c;
XSc0x01c vc0x01c;
X
Xtypedef struct {char a; int b: 0x19; short c;} Sc0x19s;
Xtypedef struct {char a; int b: 0x02; short c;} Sc0x02s;
Xtypedef struct {char a; int b: 0x20; short c;} Sc0x20s;
Xtypedef struct {char a; int b: 0x04; short c;} Sc0x04s;
Xtypedef struct {char a; int b: 0x05; short c;} Sc0x05s;
Xtypedef struct {char a; int b: 0x08; short c;} Sc0x08s;
Xtypedef struct {char a; int b: 0x09; short c;} Sc0x09s;
Xtypedef struct {char a; int b: 0x0c; short c;} Sc0x0cs;
Xtypedef struct {char a; int b: 0x10; short c;} Sc0x10s;
Xtypedef struct {char a; int b: 0x11; short c;} Sc0x11s;
Xtypedef struct {char a; int b: 0x14; short c;} Sc0x14s;
Xtypedef struct {char a; int b: 0x17; short c;} Sc0x17s;
Xtypedef struct {char a; int b: 0x18; short c;} Sc0x18s;
Xtypedef struct {char a; int b: 0x01; short c;} Sc0x01s;
XSc0x19s vc0x19s;
XSc0x02s vc0x02s;
XSc0x20s vc0x20s;
XSc0x04s vc0x04s;
XSc0x05s vc0x05s;
XSc0x08s vc0x08s;
XSc0x09s vc0x09s;
XSc0x0cs vc0x0cs;
XSc0x10s vc0x10s;
XSc0x11s vc0x11s;
XSc0x14s vc0x14s;
XSc0x17s vc0x17s;
XSc0x18s vc0x18s;
XSc0x01s vc0x01s;
X
Xtypedef struct {char a; int b: 0x19; int c: 0x19;} Sc0x190x19;
Xtypedef struct {char a; int b: 0x02; int c: 0x02;} Sc0x020x02;
Xtypedef struct {char a; int b: 0x20; int c: 0x20;} Sc0x200x20;
Xtypedef struct {char a; int b: 0x04; int c: 0x04;} Sc0x040x04;
Xtypedef struct {char a; int b: 0x05; int c: 0x05;} Sc0x050x05;
Xtypedef struct {char a; int b: 0x08; int c: 0x08;} Sc0x080x08;
Xtypedef struct {char a; int b: 0x09; int c: 0x09;} Sc0x090x09;
Xtypedef struct {char a; int b: 0x0c; int c: 0x0c;} Sc0x0c0x0c;
Xtypedef struct {char a; int b: 0x10; int c: 0x10;} Sc0x100x10;
Xtypedef struct {char a; int b: 0x11; int c: 0x11;} Sc0x110x11;
Xtypedef struct {char a; int b: 0x14; int c: 0x14;} Sc0x140x14;
Xtypedef struct {char a; int b: 0x17; int c: 0x17;} Sc0x170x17;
Xtypedef struct {char a; int b: 0x18; int c: 0x18;} Sc0x180x18;
Xtypedef struct {char a; int b: 0x01; int c: 0x01;} Sc0x010x01;
XSc0x190x19 vc0x190x19;
XSc0x020x02 vc0x020x02;
XSc0x200x20 vc0x200x20;
XSc0x040x04 vc0x040x04;
XSc0x050x05 vc0x050x05;
XSc0x080x08 vc0x080x08;
XSc0x090x09 vc0x090x09;
XSc0x0c0x0c vc0x0c0x0c;
XSc0x100x10 vc0x100x10;
XSc0x110x11 vc0x110x11;
XSc0x140x14 vc0x140x14;
XSc0x170x17 vc0x170x17;
XSc0x180x18 vc0x180x18;
XSc0x010x01 vc0x010x01;
X
Xtypedef struct {char a; int b: 0x19; int c: 0x19; char d;} Sc0x190x19c;
Xtypedef struct {char a; int b: 0x02; int c: 0x02; char d;} Sc0x020x02c;
Xtypedef struct {char a; int b: 0x20; int c: 0x20; char d;} Sc0x200x20c;
Xtypedef struct {char a; int b: 0x04; int c: 0x04; char d;} Sc0x040x04c;
Xtypedef struct {char a; int b: 0x05; int c: 0x05; char d;} Sc0x050x05c;
Xtypedef struct {char a; int b: 0x08; int c: 0x08; char d;} Sc0x080x08c;
Xtypedef struct {char a; int b: 0x09; int c: 0x09; char d;} Sc0x090x09c;
Xtypedef struct {char a; int b: 0x0c; int c: 0x0c; char d;} Sc0x0c0x0cc;
Xtypedef struct {char a; int b: 0x10; int c: 0x10; char d;} Sc0x100x10c;
Xtypedef struct {char a; int b: 0x11; int c: 0x11; char d;} Sc0x110x11c;
Xtypedef struct {char a; int b: 0x14; int c: 0x14; char d;} Sc0x140x14c;
Xtypedef struct {char a; int b: 0x17; int c: 0x17; char d;} Sc0x170x17c;
Xtypedef struct {char a; int b: 0x18; int c: 0x18; char d;} Sc0x180x18c;
Xtypedef struct {char a; int b: 0x01; int c: 0x01; char d;} Sc0x010x01c;
XSc0x190x19c vc0x190x19c;
XSc0x020x02c vc0x020x02c;
XSc0x200x20c vc0x200x20c;
XSc0x040x04c vc0x040x04c;
XSc0x050x05c vc0x050x05c;
XSc0x080x08c vc0x080x08c;
XSc0x090x09c vc0x090x09c;
XSc0x0c0x0cc vc0x0c0x0cc;
XSc0x100x10c vc0x100x10c;
XSc0x110x11c vc0x110x11c;
XSc0x140x14c vc0x140x14c;
XSc0x170x17c vc0x170x17c;
XSc0x180x18c vc0x180x18c;
XSc0x010x01c vc0x010x01c;
X
Xtypedef struct {char a; int b: 0x19; int c: 0x19; short d;} Sc0x190x19s;
Xtypedef struct {char a; int b: 0x02; int c: 0x02; short d;} Sc0x020x02s;
Xtypedef struct {char a; int b: 0x20; int c: 0x20; short d;} Sc0x200x20s;
Xtypedef struct {char a; int b: 0x04; int c: 0x04; short d;} Sc0x040x04s;
Xtypedef struct {char a; int b: 0x05; int c: 0x05; short d;} Sc0x050x05s;
Xtypedef struct {char a; int b: 0x08; int c: 0x08; short d;} Sc0x080x08s;
Xtypedef struct {char a; int b: 0x09; int c: 0x09; short d;} Sc0x090x09s;
Xtypedef struct {char a; int b: 0x0c; int c: 0x0c; short d;} Sc0x0c0x0cs;
Xtypedef struct {char a; int b: 0x10; int c: 0x10; short d;} Sc0x100x10s;
Xtypedef struct {char a; int b: 0x11; int c: 0x11; short d;} Sc0x110x11s;
Xtypedef struct {char a; int b: 0x14; int c: 0x14; short d;} Sc0x140x14s;
Xtypedef struct {char a; int b: 0x17; int c: 0x17; short d;} Sc0x170x17s;
Xtypedef struct {char a; int b: 0x18; int c: 0x18; short d;} Sc0x180x18s;
Xtypedef struct {char a; int b: 0x01; int c: 0x01; short d;} Sc0x010x01s;
XSc0x190x19s vc0x190x19s;
XSc0x020x02s vc0x020x02s;
XSc0x200x20s vc0x200x20s;
XSc0x040x04s vc0x040x04s;
XSc0x050x05s vc0x050x05s;
XSc0x080x08s vc0x080x08s;
XSc0x090x09s vc0x090x09s;
XSc0x0c0x0cs vc0x0c0x0cs;
XSc0x100x10s vc0x100x10s;
XSc0x110x11s vc0x110x11s;
XSc0x140x14s vc0x140x14s;
XSc0x170x17s vc0x170x17s;
XSc0x180x18s vc0x180x18s;
XSc0x010x01s vc0x010x01s;
X
X#include "types.h"
X
X
Xtry (n)
X int n;
X{
X int i;
X int padded = 0;
X int this_bitfield_unit_start;
X int last_was_bitfield = 0;
X
X size = 0;
X align = 1;
X
X for (i = 0; i < n; i++) {
X if (p[i]) {
X int last;
X
X if (last_was_bitfield) {
X if (BITFIELD_UNITS_OVERLAP) {
X last = rounddown (size, BITFIELD_UNIT_ALIGN) + BITFIELD_UNIT_SIZE; }
X else {
X last = this_bitfield_unit_start + BITFIELD_UNIT_SIZE; }}
X else {
X if (FIELD_PAD_BITFIELD) {
X this_bitfield_unit_start = roundup (size, BITFIELD_UNIT_ALIGN);
X size = this_bitfield_unit_start; }
X else {
X this_bitfield_unit_start = rounddown (size, BITFIELD_UNIT_ALIGN); }
X last = this_bitfield_unit_start + BITFIELD_UNIT_SIZE; }
X
X if (size + s[i] <= last) {
X start [i] = size;
X size += s[i]; }
X else {
X this_bitfield_unit_start = roundup (size, BITFIELD_UNIT_ALIGN);
X start [i] = this_bitfield_unit_start;
X size = this_bitfield_unit_start + s[i]; }
X
X align = MAX (align, BITFIELD_SIZE_ALIGN [s[i]]); }
X
X else {
X if (last_was_bitfield && BITFIELD_PAD_FIELD) {
X size = roundup (size, BITFIELD_UNIT_ALIGN); }
X start[i] = roundup (size, a[i]);
X size = start[i] + s[i];
X align = MAX (align, a[i]); }
X
X last_was_bitfield = p[i];
X stop [i] = start[i] + s[i] - 1; }
X
X size = roundup (size, align);
X for (i = 0; i < NUMBER_PAD_SIZES; i++) {
X if (size <= PAD_SIZES [i]) {
X size = PAD_SIZES [i];
X padded = 1;
X break; }}
X if (padded == 0) {
X size = roundup (size, PAD_SIZES [NUMBER_PAD_SIZES - 1]); }
X}
X
Xint wrong (si, al, nb_fields)
X int si, al, nb_fields;
X{
X int i;
X
X try (nb_fields);
X if ((size != si) || (align != al)) {
X if (report_losses) {
X printf ("%d %d %d %d %d FAILS on %s",
X BITFIELD_UNIT_SIZE,
X BITFIELD_UNIT_ALIGN,
X FIELD_PAD_BITFIELD,
X BITFIELD_PAD_FIELD,
X BITFIELD_UNITS_OVERLAP,
X block);
X for (i = 0; i < nb_fields; i++) {
X if (p[i]) {
X printf (" %d", s[i]); }}
X printf (": %d, %d instead of %d, %d\n", size, align, si, al); }
X return 1; }
X
X return 0;
X}
X
Xint
X try_OVERLAP[] = {0, 1},
X try_SIZE[] = {8, 16, 32, 64, 128},
X try_ALIGN[] = {8, 16, 32, 64, 128},
X try_FPB[] = {0, 1},
X try_BPF[] = {0, 1};
X
Xint search ()
X{
X int winner =0;
X int t_OVERLAP, t_SIZE, t_ALIGN, t_FPB, t_BPF;
X
X for (t_SIZE = 0;
X t_SIZE < sizeof (try_SIZE) / sizeof (int);
X t_SIZE++) {
X BITFIELD_UNIT_SIZE = try_SIZE [t_SIZE];
X
X for (t_ALIGN = 0;
X t_ALIGN < sizeof (try_ALIGN) / sizeof (int);
X t_ALIGN++) {
X BITFIELD_UNIT_ALIGN = try_ALIGN [t_ALIGN];
X
X for (t_FPB = 0;
X t_FPB < sizeof (try_FPB) / sizeof (int);
X t_FPB++) {
X FIELD_PAD_BITFIELD = try_FPB [t_FPB];
X
X for (t_BPF = 0;
X t_BPF < sizeof (try_BPF) / sizeof (int);
X t_BPF++) {
X BITFIELD_PAD_FIELD = try_BPF [t_BPF];
X
X for (t_OVERLAP = 0;
X t_OVERLAP < sizeof (try_OVERLAP) / sizeof (int);
X t_OVERLAP++) {
X BITFIELD_UNITS_OVERLAP = try_OVERLAP [t_OVERLAP];
X
X block = "S_";
X a[0] = 1; p[0] = 1;
X s[0] = 0x19; if (wrong (SZ (S0x19), AL (S0x19), 1)) continue;
X s[0] = 0x02; if (wrong (SZ (S0x02), AL (S0x02), 1)) continue;
X s[0] = 0x20; if (wrong (SZ (S0x20), AL (S0x20), 1)) continue;
X s[0] = 0x04; if (wrong (SZ (S0x04), AL (S0x04), 1)) continue;
X s[0] = 0x05; if (wrong (SZ (S0x05), AL (S0x05), 1)) continue;
X s[0] = 0x08; if (wrong (SZ (S0x08), AL (S0x08), 1)) continue;
X s[0] = 0x09; if (wrong (SZ (S0x09), AL (S0x09), 1)) continue;
X s[0] = 0x0c; if (wrong (SZ (S0x0c), AL (S0x0c), 1)) continue;
X s[0] = 0x10; if (wrong (SZ (S0x10), AL (S0x10), 1)) continue;
X s[0] = 0x11; if (wrong (SZ (S0x11), AL (S0x11), 1)) continue;
X s[0] = 0x14; if (wrong (SZ (S0x14), AL (S0x14), 1)) continue;
X s[0] = 0x17; if (wrong (SZ (S0x17), AL (S0x17), 1)) continue;
X s[0] = 0x18; if (wrong (SZ (S0x18), AL (S0x18), 1)) continue;
X s[0] = 0x01; if (wrong (SZ (S0x01), AL (S0x01), 1)) continue;
X
X block = "Sc_";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[1] = 0x19; if (wrong (SZ (Sc0x19), AL (Sc0x19), 2)) continue;
X s[1] = 0x02; if (wrong (SZ (Sc0x02), AL (Sc0x02), 2)) continue;
X s[1] = 0x20; if (wrong (SZ (Sc0x20), AL (Sc0x20), 2)) continue;
X s[1] = 0x04; if (wrong (SZ (Sc0x04), AL (Sc0x04), 2)) continue;
X s[1] = 0x05; if (wrong (SZ (Sc0x05), AL (Sc0x05), 2)) continue;
X s[1] = 0x08; if (wrong (SZ (Sc0x08), AL (Sc0x08), 2)) continue;
X s[1] = 0x09; if (wrong (SZ (Sc0x09), AL (Sc0x09), 2)) continue;
X s[1] = 0x0c; if (wrong (SZ (Sc0x0c), AL (Sc0x0c), 2)) continue;
X s[1] = 0x10; if (wrong (SZ (Sc0x10), AL (Sc0x10), 2)) continue;
X s[1] = 0x11; if (wrong (SZ (Sc0x11), AL (Sc0x11), 2)) continue;
X s[1] = 0x14; if (wrong (SZ (Sc0x14), AL (Sc0x14), 2)) continue;
X s[1] = 0x17; if (wrong (SZ (Sc0x17), AL (Sc0x17), 2)) continue;
X s[1] = 0x18; if (wrong (SZ (Sc0x18), AL (Sc0x18), 2)) continue;
X s[1] = 0x01; if (wrong (SZ (Sc0x01), AL (Sc0x01), 2)) continue;
X
X block = "Ss_";
X s[0] = s_short; a[0] = a_short; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[1] = 0x19; if (wrong (SZ (Ss0x19), AL (Ss0x19), 2)) continue;
X s[1] = 0x02; if (wrong (SZ (Ss0x02), AL (Ss0x02), 2)) continue;
X s[1] = 0x20; if (wrong (SZ (Ss0x20), AL (Ss0x20), 2)) continue;
X s[1] = 0x04; if (wrong (SZ (Ss0x04), AL (Ss0x04), 2)) continue;
X s[1] = 0x05; if (wrong (SZ (Ss0x05), AL (Ss0x05), 2)) continue;
X s[1] = 0x08; if (wrong (SZ (Ss0x08), AL (Ss0x08), 2)) continue;
X s[1] = 0x09; if (wrong (SZ (Ss0x09), AL (Ss0x09), 2)) continue;
X s[1] = 0x0c; if (wrong (SZ (Ss0x0c), AL (Ss0x0c), 2)) continue;
X s[1] = 0x10; if (wrong (SZ (Ss0x10), AL (Ss0x10), 2)) continue;
X s[1] = 0x11; if (wrong (SZ (Ss0x11), AL (Ss0x11), 2)) continue;
X s[1] = 0x14; if (wrong (SZ (Ss0x14), AL (Ss0x14), 2)) continue;
X s[1] = 0x17; if (wrong (SZ (Ss0x17), AL (Ss0x17), 2)) continue;
X s[1] = 0x18; if (wrong (SZ (Ss0x18), AL (Ss0x18), 2)) continue;
X s[1] = 0x01; if (wrong (SZ (Ss0x01), AL (Ss0x01), 2)) continue;
X
X block = "Si_";
X s[0] = s_int; a[0] = a_int; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[1] = 0x19; if (wrong (SZ (Si0x19), AL (Si0x19), 2)) continue;
X s[1] = 0x02; if (wrong (SZ (Si0x02), AL (Si0x02), 2)) continue;
X s[1] = 0x20; if (wrong (SZ (Si0x20), AL (Si0x20), 2)) continue;
X s[1] = 0x04; if (wrong (SZ (Si0x04), AL (Si0x04), 2)) continue;
X s[1] = 0x05; if (wrong (SZ (Si0x05), AL (Si0x05), 2)) continue;
X s[1] = 0x08; if (wrong (SZ (Si0x08), AL (Si0x08), 2)) continue;
X s[1] = 0x09; if (wrong (SZ (Si0x09), AL (Si0x09), 2)) continue;
X s[1] = 0x0c; if (wrong (SZ (Si0x0c), AL (Si0x0c), 2)) continue;
X s[1] = 0x10; if (wrong (SZ (Si0x10), AL (Si0x10), 2)) continue;
X s[1] = 0x11; if (wrong (SZ (Si0x11), AL (Si0x11), 2)) continue;
X s[1] = 0x14; if (wrong (SZ (Si0x14), AL (Si0x14), 2)) continue;
X s[1] = 0x17; if (wrong (SZ (Si0x17), AL (Si0x17), 2)) continue;
X s[1] = 0x18; if (wrong (SZ (Si0x18), AL (Si0x18), 2)) continue;
X s[1] = 0x01; if (wrong (SZ (Si0x01), AL (Si0x01), 2)) continue;
X
X block = "Sl_";
X s[0] = s_long; a[0] = a_long; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[1] = 0x19; if (wrong (SZ (Sl0x19), AL (Sl0x19), 2)) continue;
X s[1] = 0x02; if (wrong (SZ (Sl0x02), AL (Sl0x02), 2)) continue;
X s[1] = 0x20; if (wrong (SZ (Sl0x20), AL (Sl0x20), 2)) continue;
X s[1] = 0x04; if (wrong (SZ (Sl0x04), AL (Sl0x04), 2)) continue;
X s[1] = 0x05; if (wrong (SZ (Sl0x05), AL (Sl0x05), 2)) continue;
X s[1] = 0x08; if (wrong (SZ (Sl0x08), AL (Sl0x08), 2)) continue;
X s[1] = 0x09; if (wrong (SZ (Sl0x09), AL (Sl0x09), 2)) continue;
X s[1] = 0x0c; if (wrong (SZ (Sl0x0c), AL (Sl0x0c), 2)) continue;
X s[1] = 0x10; if (wrong (SZ (Sl0x10), AL (Sl0x10), 2)) continue;
X s[1] = 0x11; if (wrong (SZ (Sl0x11), AL (Sl0x11), 2)) continue;
X s[1] = 0x14; if (wrong (SZ (Sl0x14), AL (Sl0x14), 2)) continue;
X s[1] = 0x17; if (wrong (SZ (Sl0x17), AL (Sl0x17), 2)) continue;
X s[1] = 0x18; if (wrong (SZ (Sl0x18), AL (Sl0x18), 2)) continue;
X s[1] = 0x01; if (wrong (SZ (Sl0x01), AL (Sl0x01), 2)) continue;
X
X block = "Sc_c";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[2] = s_char; a[2] = a_char; p[2] = 0;
X s[1] = 0x19; if (wrong (SZ (Sc0x19c), AL (Sc0x19c), 3)) continue;
X s[1] = 0x02; if (wrong (SZ (Sc0x02c), AL (Sc0x02c), 3)) continue;
X s[1] = 0x20; if (wrong (SZ (Sc0x20c), AL (Sc0x20c), 3)) continue;
X s[1] = 0x04; if (wrong (SZ (Sc0x04c), AL (Sc0x04c), 3)) continue;
X s[1] = 0x05; if (wrong (SZ (Sc0x05c), AL (Sc0x05c), 3)) continue;
X s[1] = 0x08; if (wrong (SZ (Sc0x08c), AL (Sc0x08c), 3)) continue;
X s[1] = 0x09; if (wrong (SZ (Sc0x09c), AL (Sc0x09c), 3)) continue;
X s[1] = 0x0c; if (wrong (SZ (Sc0x0cc), AL (Sc0x0cc), 3)) continue;
X s[1] = 0x10; if (wrong (SZ (Sc0x10c), AL (Sc0x10c), 3)) continue;
X s[1] = 0x11; if (wrong (SZ (Sc0x11c), AL (Sc0x11c), 3)) continue;
X s[1] = 0x14; if (wrong (SZ (Sc0x14c), AL (Sc0x14c), 3)) continue;
X s[1] = 0x17; if (wrong (SZ (Sc0x17c), AL (Sc0x17c), 3)) continue;
X s[1] = 0x18; if (wrong (SZ (Sc0x18c), AL (Sc0x18c), 3)) continue;
X s[1] = 0x01; if (wrong (SZ (Sc0x01c), AL (Sc0x01c), 3)) continue;
X
X block = "Sc__";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X a[2] = 1; p[2] = 1;
X s[1]=s[2]=0x19; if (wrong (SZ (Sc0x190x19), AL (Sc0x190x19), 3)) continue;
X s[1]=s[2]=0x02; if (wrong (SZ (Sc0x020x02), AL (Sc0x020x02), 3)) continue;
X s[1]=s[2]=0x20; if (wrong (SZ (Sc0x200x20), AL (Sc0x200x20), 3)) continue;
X s[1]=s[2]=0x04; if (wrong (SZ (Sc0x040x04), AL (Sc0x040x04), 3)) continue;
X s[1]=s[2]=0x05; if (wrong (SZ (Sc0x050x05), AL (Sc0x050x05), 3)) continue;
X s[1]=s[2]=0x08; if (wrong (SZ (Sc0x080x08), AL (Sc0x080x08), 3)) continue;
X s[1]=s[2]=0x09; if (wrong (SZ (Sc0x090x09), AL (Sc0x090x09), 3)) continue;
X s[1]=s[2]=0x0c; if (wrong (SZ (Sc0x0c0x0c), AL (Sc0x0c0x0c), 3)) continue;
X s[1]=s[2]=0x10; if (wrong (SZ (Sc0x100x10), AL (Sc0x100x10), 3)) continue;
X s[1]=s[2]=0x11; if (wrong (SZ (Sc0x110x11), AL (Sc0x110x11), 3)) continue;
X s[1]=s[2]=0x14; if (wrong (SZ (Sc0x140x14), AL (Sc0x140x14), 3)) continue;
X s[1]=s[2]=0x17; if (wrong (SZ (Sc0x170x17), AL (Sc0x170x17), 3)) continue;
X s[1]=s[2]=0x18; if (wrong (SZ (Sc0x180x18), AL (Sc0x180x18), 3)) continue;
X s[1]=s[2]=0x01; if (wrong (SZ (Sc0x010x01), AL (Sc0x010x01), 3)) continue;
X
X block = "Sc__c";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X a[2] = 1; p[2] = 1;
X s[3] = s_char; a[3] = a_char; p[3] = 0;
X s[1]=s[2]=0x19; if (wrong (SZ (Sc0x190x19c), AL (Sc0x190x19c), 4)) continue;
X s[1]=s[2]=0x02; if (wrong (SZ (Sc0x020x02c), AL (Sc0x020x02c), 4)) continue;
X s[1]=s[2]=0x20; if (wrong (SZ (Sc0x200x20c), AL (Sc0x200x20c), 4)) continue;
X s[1]=s[2]=0x04; if (wrong (SZ (Sc0x040x04c), AL (Sc0x040x04c), 4)) continue;
X s[1]=s[2]=0x05; if (wrong (SZ (Sc0x050x05c), AL (Sc0x050x05c), 4)) continue;
X s[1]=s[2]=0x08; if (wrong (SZ (Sc0x080x08c), AL (Sc0x080x08c), 4)) continue;
X s[1]=s[2]=0x09; if (wrong (SZ (Sc0x090x09c), AL (Sc0x090x09c), 4)) continue;
X s[1]=s[2]=0x0c; if (wrong (SZ (Sc0x0c0x0cc), AL (Sc0x0c0x0cc), 4)) continue;
X s[1]=s[2]=0x10; if (wrong (SZ (Sc0x100x10c), AL (Sc0x100x10c), 4)) continue;
X s[1]=s[2]=0x11; if (wrong (SZ (Sc0x110x11c), AL (Sc0x110x11c), 4)) continue;
X s[1]=s[2]=0x14; if (wrong (SZ (Sc0x140x14c), AL (Sc0x140x14c), 4)) continue;
X s[1]=s[2]=0x17; if (wrong (SZ (Sc0x170x17c), AL (Sc0x170x17c), 4)) continue;
X s[1]=s[2]=0x18; if (wrong (SZ (Sc0x180x18c), AL (Sc0x180x18c), 4)) continue;
X s[1]=s[2]=0x01; if (wrong (SZ (Sc0x010x01c), AL (Sc0x010x01c), 4)) continue;
X
X block = "Sc_s";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X s[2] = s_short; a[2] = a_short; p[2] = 0;
X s[1] = 0x19; if (wrong (SZ (Sc0x19s), AL (Sc0x19s), 3)) continue;
X s[1] = 0x02; if (wrong (SZ (Sc0x02s), AL (Sc0x02s), 3)) continue;
X s[1] = 0x20; if (wrong (SZ (Sc0x20s), AL (Sc0x20s), 3)) continue;
X s[1] = 0x04; if (wrong (SZ (Sc0x04s), AL (Sc0x04s), 3)) continue;
X s[1] = 0x05; if (wrong (SZ (Sc0x05s), AL (Sc0x05s), 3)) continue;
X s[1] = 0x08; if (wrong (SZ (Sc0x08s), AL (Sc0x08s), 3)) continue;
X s[1] = 0x09; if (wrong (SZ (Sc0x09s), AL (Sc0x09s), 3)) continue;
X s[1] = 0x0c; if (wrong (SZ (Sc0x0cs), AL (Sc0x0cs), 3)) continue;
X s[1] = 0x10; if (wrong (SZ (Sc0x10s), AL (Sc0x10s), 3)) continue;
X s[1] = 0x11; if (wrong (SZ (Sc0x11s), AL (Sc0x11s), 3)) continue;
X s[1] = 0x14; if (wrong (SZ (Sc0x14s), AL (Sc0x14s), 3)) continue;
X s[1] = 0x17; if (wrong (SZ (Sc0x17s), AL (Sc0x17s), 3)) continue;
X s[1] = 0x18; if (wrong (SZ (Sc0x18s), AL (Sc0x18s), 3)) continue;
X s[1] = 0x01; if (wrong (SZ (Sc0x01s), AL (Sc0x01s), 3)) continue;
X
X block = "Sc__s";
X s[0] = s_char; a[0] = a_char; p[0] = 0;
X a[1] = 1; p[1] = 1;
X a[2] = 1; p[2] = 1;
X s[3] = s_short; a[3] = a_short; p[3] = 0;
X s[1]=s[2]=0x19; if (wrong (SZ (Sc0x190x19s), AL (Sc0x190x19s), 4)) continue;
X s[1]=s[2]=0x02; if (wrong (SZ (Sc0x020x02s), AL (Sc0x020x02s), 4)) continue;
X s[1]=s[2]=0x20; if (wrong (SZ (Sc0x200x20s), AL (Sc0x200x20s), 4)) continue;
X s[1]=s[2]=0x04; if (wrong (SZ (Sc0x040x04s), AL (Sc0x040x04s), 4)) continue;
X s[1]=s[2]=0x05; if (wrong (SZ (Sc0x050x05s), AL (Sc0x050x05s), 4)) continue;
X s[1]=s[2]=0x08; if (wrong (SZ (Sc0x080x08s), AL (Sc0x080x08s), 4)) continue;
X s[1]=s[2]=0x09; if (wrong (SZ (Sc0x090x09s), AL (Sc0x090x09s), 4)) continue;
X s[1]=s[2]=0x0c; if (wrong (SZ (Sc0x0c0x0cs), AL (Sc0x0c0x0cs), 4)) continue;
X s[1]=s[2]=0x10; if (wrong (SZ (Sc0x100x10s), AL (Sc0x100x10s), 4)) continue;
X s[1]=s[2]=0x11; if (wrong (SZ (Sc0x110x11s), AL (Sc0x110x11s), 4)) continue;
X s[1]=s[2]=0x14; if (wrong (SZ (Sc0x140x14s), AL (Sc0x140x14s), 4)) continue;
X s[1]=s[2]=0x17; if (wrong (SZ (Sc0x170x17s), AL (Sc0x170x17s), 4)) continue;
X s[1]=s[2]=0x18; if (wrong (SZ (Sc0x180x18s), AL (Sc0x180x18s), 4)) continue;
X s[1]=s[2]=0x01; if (wrong (SZ (Sc0x010x01s), AL (Sc0x010x01s), 4)) continue;
X
X#include "code.h"
X
X winner = 1;
X printf ("\nBITFIELD_UNIT_SIZE %d\n", BITFIELD_UNIT_SIZE);
X printf ("BITFIELD_UNIT_ALIGN %d\n", BITFIELD_UNIT_ALIGN);
X printf ("FIELD_PAD_BITFIELD %d\n", FIELD_PAD_BITFIELD);
X printf ("BITFIELD_PAD_FIELD %d\n", BITFIELD_PAD_FIELD);
X printf ("BITFIELD_UNITS_OVERLAP %d\n", BITFIELD_UNITS_OVERLAP);
X }}}}}
X
X return winner;
X}
X
X
Xstatic int c[33] = {
X sizeof (SC0x01),
X sizeof (SC0x02),
X sizeof (SC0x03),
X sizeof (SC0x04),
X sizeof (SC0x05),
X sizeof (SC0x06),
X sizeof (SC0x07),
X sizeof (SC0x08),
X sizeof (SC0x09),
X sizeof (SC0x0a),
X sizeof (SC0x0b),
X sizeof (SC0x0c),
X sizeof (SC0x0d),
X sizeof (SC0x0e),
X sizeof (SC0x0f),
X sizeof (SC0x10),
X sizeof (SC0x11),
X sizeof (SC0x12),
X sizeof (SC0x13),
X sizeof (SC0x14),
X sizeof (SC0x15),
X sizeof (SC0x16),
X sizeof (SC0x17),
X sizeof (SC0x18),
X sizeof (SC0x19),
X sizeof (SC0x1a),
X sizeof (SC0x1b),
X sizeof (SC0x1c),
X sizeof (SC0x1d),
X sizeof (SC0x1e),
X sizeof (SC0x1f),
X sizeof (SC0x20),
X 0};
X
X
Xfind_pad_sizes ()
X{
X int i, j, ok;
X
X for (i = 0; i < 24; i++) {
X ok = 1;
X for (j = i + 1; j < 24; j++) {
X if (c[j] != roundup (j+1, c[i])) {
X ok = 0; }}
X if (ok == 1) {
X NUMBER_PAD_SIZES = 0;
X for (j = 0; j <= i; j++) {
X if ((NUMBER_PAD_SIZES == 0) || (c[j] != c[NUMBER_PAD_SIZES-1])) {
X printf ("PAD_SIZE = %d\n", c [j] * BITS_PER_BYTE); }
X PAD_SIZES [NUMBER_PAD_SIZES++] = c[j] * BITS_PER_BYTE; }}
X return; }
X}
X
Xfind_bits_per_byte ()
X{
X char c;
X int b;
X
X c = 1;
X b = 0;
X do { c = c << 1;
X b++; } while (c != 0);
X
X BITS_PER_BYTE = b;
X printf ("\nBITS PER BYTE = %d\n", b);
X}
X
X
Xbasic_sizes_and_alignments ()
X{
X
X s_char = SZ (char);
X a_char = AL (char);
X s_short = SZ (short);
X a_short = AL (short);
X s_int = SZ (int);
X a_int = AL (int);
X s_long = SZ (long);
X a_long = AL (long);
X
X s_float = SZ (float);
X a_float = AL (float);
X s_double = SZ (double);
X a_double = AL (double);
X
X printf ("SIZEOF char = %d\n", s_char);
X printf ("ALIGNOF char = %d\n", a_char);
X printf ("SIZEOF short = %d\n", s_short);
X printf ("ALIGNOF short = %d\n", a_short);
X printf ("SIZEOF int = %d\n", s_int);
X printf ("ALIGNOF int = %d\n", a_int);
X printf ("SIZEOF long = %d\n", s_long);
X printf ("ALIGNOF long = %d\n", a_long);
X printf ("SIZEOF float = %d\n", s_float);
X printf ("ALIGNOF float = %d\n", a_float);
X printf ("SIZEOF double = %d\n", s_double);
X printf ("ALIGNOF double = %d\n", a_double);
X}
X
X#define SHOW(T,Tn) \
X { T *a; int i, j; \
X a = (T *) &v; \
X for (i = 0; i < sizeof (v)/sizeof(T); i++) { a[i] = 0; } \
X printf ("%s; size = %d, seen as %s\n", desc, sizeof (v), Tn); \
X for (i = 0; i < sizeof (v) / sizeof(T); i++) { \
X for (j = 0; j < BITS_PER_BYTE * sizeof(T); j++) { \
X a[i] = 1 << j; \
X PRINT; } \
X a[i] = 0; }}
X
Xbit_positions ()
X{
X printf ("\n\nBIT POSITIONS\n");
X
X { short v;
X char *desc = "short";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d\n", i, j, v);
X SHOW(char, "char") }
X
X { int v;
X char *desc = "int";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d\n", i, j, v);
X SHOW(short, "short") }
X
X { long v;
X char *desc = "long";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d\n", i, j, v);
X SHOW(int, "int") }
X
X { struct {char a; int b:23; int c:9; char d;} v;
X char *desc = "struct {char, int :23, int :9, char}";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d, %d, %d, %d\n", i,j,v.a,v.b,v.c,v.d);
X SHOW(char, "char") }
X
X { struct {char a; int b:23; int c:9;} v;
X char *desc = "struct {char, int :23, int :9}";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d, %d, %d, %d\n", i, j, v.a, v.b, v.c);
X SHOW(char, "char") }
X
X { struct {int b:23; int c:9;} v;
X char *desc = "struct {int:23, int:9}";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d, %d\n", i, j, v.b, v.c);
X SHOW(char, "char") }
X
X { struct {int b:10; int c:24;} v;
X char *desc = "struct {int:10, int:24}";
X#undef PRINT
X#define PRINT printf (" %d, %d = %d, %d\n", i, j, v.b, v.c);
X SHOW(char, "char") }
X}
X
Xfind_bitfield_aligns ()
X{
X BITFIELD_SIZE_ALIGN [0x01] = SZ (S0x01);
X BITFIELD_SIZE_ALIGN [0x02] = SZ (S0x02);
X BITFIELD_SIZE_ALIGN [0x03] = SZ (S0x03);
X BITFIELD_SIZE_ALIGN [0x04] = SZ (S0x04);
X BITFIELD_SIZE_ALIGN [0x05] = SZ (S0x05);
X BITFIELD_SIZE_ALIGN [0x06] = SZ (S0x06);
X BITFIELD_SIZE_ALIGN [0x07] = SZ (S0x07);
X BITFIELD_SIZE_ALIGN [0x08] = SZ (S0x08);
X BITFIELD_SIZE_ALIGN [0x09] = SZ (S0x09);
X BITFIELD_SIZE_ALIGN [0x0a] = SZ (S0x0a);
X BITFIELD_SIZE_ALIGN [0x0b] = SZ (S0x0b);
X BITFIELD_SIZE_ALIGN [0x0c] = SZ (S0x0c);
X BITFIELD_SIZE_ALIGN [0x0d] = SZ (S0x0d);
X BITFIELD_SIZE_ALIGN [0x0e] = SZ (S0x0e);
X BITFIELD_SIZE_ALIGN [0x0f] = SZ (S0x0f);
X BITFIELD_SIZE_ALIGN [0x10] = SZ (S0x10);
X BITFIELD_SIZE_ALIGN [0x11] = SZ (S0x11);
X BITFIELD_SIZE_ALIGN [0x12] = SZ (S0x12);
X BITFIELD_SIZE_ALIGN [0x13] = SZ (S0x13);
X BITFIELD_SIZE_ALIGN [0x14] = SZ (S0x14);
X BITFIELD_SIZE_ALIGN [0x15] = SZ (S0x15);
X BITFIELD_SIZE_ALIGN [0x16] = SZ (S0x16);
X BITFIELD_SIZE_ALIGN [0x17] = SZ (S0x17);
X BITFIELD_SIZE_ALIGN [0x18] = SZ (S0x18);
X BITFIELD_SIZE_ALIGN [0x19] = SZ (S0x19);
X BITFIELD_SIZE_ALIGN [0x1a] = SZ (S0x1a);
X BITFIELD_SIZE_ALIGN [0x1b] = SZ (S0x1b);
X BITFIELD_SIZE_ALIGN [0x1c] = SZ (S0x1c);
X BITFIELD_SIZE_ALIGN [0x1d] = SZ (S0x1d);
X BITFIELD_SIZE_ALIGN [0x1e] = SZ (S0x1e);
X BITFIELD_SIZE_ALIGN [0x1f] = SZ (S0x1f);
X BITFIELD_SIZE_ALIGN [0x20] = SZ (S0x20);
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x01, SZ (S0x01));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x02, SZ (S0x02));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x03, SZ (S0x03));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x04, SZ (S0x04));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x05, SZ (S0x05));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x06, SZ (S0x06));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x07, SZ (S0x07));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x08, SZ (S0x08));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x09, SZ (S0x09));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0a, SZ (S0x0a));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0b, SZ (S0x0b));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0c, SZ (S0x0c));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0d, SZ (S0x0d));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0e, SZ (S0x0e));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x0f, SZ (S0x0f));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x10, SZ (S0x10));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x11, SZ (S0x11));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x12, SZ (S0x12));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x13, SZ (S0x13));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x14, SZ (S0x14));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x15, SZ (S0x15));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x16, SZ (S0x16));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x17, SZ (S0x17));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x18, SZ (S0x18));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x19, SZ (S0x19));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1a, SZ (S0x1a));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1b, SZ (S0x1b));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1c, SZ (S0x1c));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1d, SZ (S0x1d));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1e, SZ (S0x1e));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x1f, SZ (S0x1f));
X printf ("BITFIELD_SIZE_ALIGN [%02d] = %d\n", 0x20, SZ (S0x20));
X
X}
X
Xmain ()
X{
X find_bits_per_byte ();
X basic_sizes_and_alignments ();
X find_pad_sizes ();
X find_bitfield_aligns ();
X report_losses = 0;
X if (search () != 1) {
X report_losses = 1;
X search (); }
X else {
X bit_positions (); }
X exit (0);
X}
SHAR_EOF
$TOUCH -am 0608225692 params.c &&
chmod 0644 params.c ||
echo "restore of params.c failed"
set `wc -c params.c`;Wc_c=$1
if test "$Wc_c" != "34762"; then
echo original size 34762, current size $Wc_c
fi
# ============= random.c ==============
echo "x - extracting random.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > random.c &&
Xenum {Tchar, Tshort, Tint, Tlong, Tfloat, Tdouble, Tbit} types;
X
Xchar* typeNames [] = {"char", "short", "int", "long", "float", "double"};
X
Xint typeFreq [] = {Tchar, Tshort, Tint, Tlong, Tfloat, Tdouble,
X Tbit, Tbit, Tbit, Tbit, Tbit, Tbit,
X Tbit, Tbit, Tbit, Tbit, Tbit, Tbit,
X Tbit, Tbit, Tbit, Tbit, Tbit, Tbit, };
X
Xint sizeFreq [] = {1, 2, 3, 5, 8, 10, 16, 17,
X 19, 20, 21, 22, 24, 27, 29, 32};
X
Xmain (argc, argv)
X int argc;
X char **argv;
X{
X int r, nfields, f, ftype, fsize, n;
X
X int ftypes = fopen ("types.h", "w", 0666);
X int fcode = fopen ("code.h", "w", 0666);
X
X if (argc <= 1) {
X n = 300; }
X else {
X n = atoi (argv[1]); }
X
X for (r = 1; r <= n; r++) {
X nfields = 5 + (rand () % 10);
X
X fprintf (ftypes, "typedef struct {");
X
X for (f = 0; f < nfields; f++) {
X ftype = typeFreq [rand () % (sizeof (typeFreq) / sizeof (int))];
X if (ftype == Tbit) {
X fsize = sizeFreq [rand () % (sizeof (sizeFreq) / sizeof (int))];
X fprintf (ftypes, "int x%d: %d; ", f, fsize);
X fprintf (fcode, "s[%d]=%d; a[%d]=1; p[%d]=1;\n", f, fsize, f, f); }
X else {
X fprintf (ftypes, "%s x%d; ", typeNames [ftype], f);
X fprintf (fcode, "s[%d]=s_%s; a[%d]=a_%s; p[%d]=0;\n",
X f, typeNames[ftype], f, typeNames [ftype], f); }
X if (f % 5 == 0) {
X fprintf (ftypes, "\n"); }}
X
X fprintf (ftypes, "} R%d; R%d v%d;\n\n", r, r, r);
X fprintf (fcode, "if (wrong (SZ (R%d), AL (R%d), %d)) continue;\n\n",
X r, r, nfields); }
X}
SHAR_EOF
$TOUCH -am 0608230192 random.c &&
chmod 0644 random.c ||
echo "restore of random.c failed"
set `wc -c random.c`;Wc_c=$1
if test "$Wc_c" != "1484"; then
echo original size 1484, current size $Wc_c
fi
# ============= Makefile ==============
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
XCFLAGS = -g
X
Xall:: get_desc clean compute_result mail_result
X
Xget_desc: FRC
X @echo "You can change CC and CFLAGS (e.g. 'make CC=mycc')"
X @echo "to test various compilers."
X @echo "Please enter a description of your system, i.e.:"
X @echo " cpu type"
X @echo " operating system and version"
X @echo " compiler and version"
X @echo "as well an any comment you want to make"
X @echo "End by <EOF>"
X @echo "Thanks for you help !"
X cat - > config
X echo "CC = " $CC >> config
X echo "CFLAGS = " $CFLAGS >> config
X
Xclean:
X rm -f code.h types.h
X
Xcode.h:
X @echo "---- generating some random structures"
X -$(CC) $(CFLAGS) -o random random.c
X -./random 300
X touch code.h types.h
X
Xcompute_result: code.h
X @echo "---- if the C compiler does not like big programs"
X @echo " you may need to run random with a smaller argument"
X $(CC) $(CFLAGS) -o params params.c
X params > result
X cat result
X
Xmail_result: FRC
X cat config result | mail -s "struct, test2" muller@src.dec.com
X
XFRC:
X
SHAR_EOF
$TOUCH -am 0608233792 Makefile &&
chmod 0644 Makefile ||
echo "restore of Makefile failed"
set `wc -c Makefile`;Wc_c=$1
if test "$Wc_c" != "979"; then
echo original size 979, current size $Wc_c
fi
exit 0
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.