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	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * ASSERTION: Declare arrays of different data types and verify that the
31  * addresses of the individual elements differ by an amount equal to the number
32  * elements separating them multiplied by the size of each element.
33  *
34  * SECTION: Pointers and Arrays/Array Declarations and Storage;
35  * 	Pointers and Arrays/Pointer Arithmetic
36  *
37  * NOTES:
38  *
39  */
40 
41 #pragma D option quiet
42 
43 char char_array[5];
44 short short_array[5];
45 int int_array[5];
46 long long_array[5];
47 long long long_long_array[5];
48 int8_t int8_array[5];
49 int16_t int16_array[5];
50 int32_t int32_array[5];
51 int64_t int64_array[5];
52 intptr_t intptr_array[5];
53 uint8_t uint8_array[5];
54 uint16_t uint16_array[5];
55 uint32_t uint32_array[5];
56 uint64_t uint64_array[5];
57 uintptr_t uintptr_array[5];
58 
59 /*
60 float float_array[5];
61 double double_array[5];
62 long double long_double_array[5];
63 
64 string string_array[5];
65 */
66 
67 struct record {
68 	char ch;
69 	int in;
70 } struct_array[5];
71 
72 struct {
73 	char ch;
74 	int in;
75 } anon_struct_array[5];
76 
77 union record {
78 	char ch;
79 	int in;
80 } union_array[5];
81 
82 union {
83 	char ch;
84 	int in;
85 } anon_union_array[5];
86 
87 enum colors {
88 	RED,
89 	GREEN,
90 	BLUE
91 } enum_array[5];
92 
93 BEGIN
94 {
95 	char_var0 = &char_array[0]; char_var2 = &char_array[2];
96 	short_var0 = &short_array[0]; short_var3 = &short_array[3];
97 	int_var3 = &int_array[3]; int_var5 = &int_array[5];
98 
99 	long_var0 = &long_array[0]; long_var4 = &long_array[4];
100 	long_long_var0 = &long_long_array[0];
101 	long_long_var2 = &long_long_array[2];
102 	int8_var3 = &int8_array[3]; int8_var5 = &int8_array[5];
103 
104 	int16_var0 = &int16_array[0]; int16_var4 = &int16_array[4];
105 	int32_var0 = &int32_array[0]; int32_var3 = &int32_array[3];
106 	int64_var0 = &int64_array[0]; int64_var1 = &int64_array[1];
107 
108 	uintptr_var0 = &uintptr_array[0]; uintptr_var2 = &uintptr_array[2];
109 	struct_var0 = &struct_array[0]; struct_var2 = &struct_array[2];
110 	anon_struct_var3 = &anon_struct_array[3];
111 	anon_struct_var5 = &anon_struct_array[5];
112 
113 	union_var0 = &union_array[0]; union_var3 = &union_array[3];
114 	anon_union_var0 = &anon_union_array[0];
115 	anon_union_var4 = &anon_union_array[4];
116 	enum_var0 = &enum_array[0]; enum_var2 = &enum_array[2];
117 
118 	printf("char_var2 - char_var0: %d\n",
119 	(int) char_var2 - (int) char_var0);
120 	printf("short_var3 - short_var0: %d\n",
121 	(int) short_var3 - (int) short_var0);
122 	printf("int_var5 - int_var3: %d\n", (int) int_var5 - (int) int_var3);
123 
124 	printf("long_var4 - long_var0: %d\n",
125 	(int) long_var4 - (int) long_var0);
126 	printf("long_long_var2 - long_long_var0: %d\n",
127 	(int) long_long_var2 - (int) long_long_var0);
128 	printf("int8_var5 - int8_var3: %d\n",
129 	(int) int8_var5 - (int) int8_var3);
130 
131 	printf("int16_var4 - int16_var0: %d\n",
132 	(int) int16_var4 - (int) int16_var0);
133 	printf("int32_var3 - int32_var0: %d\n",
134 	(int) int32_var3 - (int) int32_var0);
135 	printf("int64_var1 - int64_var0: %d\n",
136 	(int) int64_var1 - (int) int64_var0);
137 
138 	printf("uintptr_var2 - uintptr_var0: %d\n",
139 	(int) uintptr_var2 - (int) uintptr_var0);
140 	printf("struct_var2 - struct_var0: %d\n",
141 	(int) struct_var2 - (int) struct_var0);
142 	printf("anon_struct_var5 - anon_struct_var3: %d\n",
143 	(int) anon_struct_var5 - (int) anon_struct_var3);
144 
145 	printf("union_var3 - union_var0: %d\n",
146 	(int) union_var3 - (int) union_var0);
147 	printf("anon_union_var4 - anon_union_var0: %d\n",
148 	(int) anon_union_var4 - (int) anon_union_var0);
149 	printf("enum_var2 - enum_var0: %d\n",
150 	(int) enum_var2 - (int) enum_var0);
151 	exit(0);
152 }
153 
154 END
155 /(2 != ((int) char_var2 - (int) char_var0)) ||
156     (6 != ((int) short_var3 - (int) short_var0)) ||
157     (8 != ((int) int_var5 - (int) int_var3)) ||
158     ((32 != ((int) long_var4 - (int) long_var0)) &&
159     (16 != ((int) long_var4 - (int) long_var0))) ||
160     (16 != ((int) long_long_var2 - (int) long_long_var0)) ||
161     (2 != ((int) int8_var5 - (int) int8_var3))
162     || (8 != ((int) int16_var4 - (int) int16_var0)) ||
163     (12 != ((int) int32_var3 - (int) int32_var0)) ||
164     (8 != ((int) int64_var1 - (int) int64_var0)) ||
165     ((16 != ((int) uintptr_var2 - (int) uintptr_var0))
166     && (8 != ((int) uintptr_var2 - (int) uintptr_var0))) ||
167     (16 != ((int) struct_var2 - (int) struct_var0)) ||
168     (16 != ((int) anon_struct_var5 - (int) anon_struct_var3))
169     || (12 != ((int) union_var3 - (int) union_var0)) ||
170     (16 != ((int) anon_union_var4 - (int) anon_union_var0)) ||
171     (8 != ((int) enum_var2 - (int) enum_var0))/
172 {
173 	exit(1);
174 }
175