1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"@(#)tst.SizeofBitField.d	1.1	06/08/28 SMI"
28
29/*
30 * ASSERTION: C and D compilers try to pack bits as efficiently as possible.
31 *
32 * SECTION: Structs and Unions/Bit-Fields
33 */
34
35#pragma D option quiet
36
37struct bitRecord1 {
38	int a : 1;
39} var1;
40
41struct bitRecord2 {
42	int a : 1;
43	int b : 3;
44} var2;
45
46struct bitRecord3 {
47	int a : 1;
48	int b : 3;
49	int c : 3;
50} var3;
51
52struct bitRecord4 {
53	int a : 1;
54	int b : 3;
55	int c : 3;
56	int d : 3;
57} var4;
58
59struct bitRecord5 {
60	int c : 12;
61	int a : 10;
62	int b : 3;
63} var5;
64
65struct bitRecord6 {
66	int a : 20;
67	int b : 3;
68	int c : 12;
69} var6;
70
71struct bitRecord7 {
72	long c : 32;
73	long long d: 9;
74	int e: 1;
75} var7;
76
77struct bitRecord8 {
78	char a : 2;
79	short b : 12;
80	long c : 32;
81} var8;
82
83struct bitRecord12 {
84	int a : 30;
85	int b : 30;
86	int c : 32;
87} var12;
88
89BEGIN
90{
91	printf("sizeof (bitRecord1): %d\n", sizeof (var1));
92	printf("sizeof (bitRecord2): %d\n", sizeof (var2));
93	printf("sizeof (bitRecord3): %d\n", sizeof (var3));
94	printf("sizeof (bitRecord4): %d\n", sizeof (var4));
95	printf("sizeof (bitRecord5): %d\n", sizeof (var5));
96	printf("sizeof (bitRecord6): %d\n", sizeof (var6));
97	printf("sizeof (bitRecord7): %d\n", sizeof (var7));
98	printf("sizeof (bitRecord8): %d\n", sizeof (var8));
99	printf("sizeof (bitRecord12): %d\n", sizeof (var12));
100	exit(0);
101}
102
103END
104/(1 != sizeof (var1)) || (2 != sizeof (var2)) || (3 != sizeof (var3)) ||
105    (4 != sizeof (var4)) || (5 != sizeof (var5)) || (6 != sizeof (var6))
106    || (7 != sizeof (var7)) || (8 != sizeof (var8)) || (12 != sizeof (var12))/
107{
108	exit(1);
109}
110