tst.SizeofDataTypes.d revision 2633:71bab08d24b2
10SN/A/*
213684SN/A * CDDL HEADER START
30SN/A *
40SN/A * The contents of this file are subject to the terms of the
50SN/A * Common Development and Distribution License (the "License").
60SN/A * You may not use this file except in compliance with the License.
72362SN/A *
80SN/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92362SN/A * or http://www.opensolaris.org/os/licensing.
100SN/A * See the License for the specific language governing permissions
110SN/A * and limitations under the License.
120SN/A *
130SN/A * When distributing Covered Code, include this CDDL HEADER in each
140SN/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150SN/A * If applicable, add the following below this CDDL HEADER, with the
160SN/A * fields enclosed by brackets "[]" replaced with your own identifying
170SN/A * information: Portions Copyright [yyyy] [name of copyright owner]
180SN/A *
190SN/A * CDDL HEADER END
200SN/A */
212362SN/A
222362SN/A/*
232362SN/A * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240SN/A * Use is subject to license terms.
250SN/A */
260SN/A
270SN/A#pragma ident	"%Z%%M%	%I%	%E% SMI"
280SN/A
290SN/A/*
300SN/A * ASSERTION: sizeof returns the size in bytes of any D expression or data
310SN/A * type.
320SN/A *
330SN/A * SECTION: Structs and Unions/Member Sizes and Offsets
340SN/A */
350SN/A#pragma D option quiet
360SN/A
370SN/Achar new_char;
380SN/Ashort new_short;
390SN/Aint new_int;
400SN/Along new_long;
4113760Snaotolong long new_long_long;
425747SN/Aint8_t new_int8;
435747SN/Aint16_t new_int16;
440SN/Aint32_t new_int32;
450SN/Aint64_t new_int64;
460SN/Aintptr_t new_intptr;
470SN/Auint8_t new_uint8;
488883SN/Auint16_t new_uint16;
499056SN/Auint32_t new_uint32;
509056SN/Auint64_t new_uint64;
5110604SN/Auintptr_t new_uintptr;
5210604SN/A
5310604SN/A/*
540SN/Afloat new_float;
559056SN/Adouble new_double;
569056SN/Along double new_long_double;
570SN/A
589056SN/Astring new_string;
599056SN/A*/
600SN/A
619056SN/Astruct record {
629056SN/A	char ch;
630SN/A	int in;
649056SN/A} new_struct;
659056SN/A
660SN/Astruct {
679056SN/A	char ch;
689056SN/A	int in;
690SN/A} anon_struct;
709056SN/A
719056SN/Aunion record {
720SN/A     char ch;
739056SN/A     int in;
749056SN/A} new_union;
7510604SN/A
7610604SN/Aunion {
7710604SN/A     char ch;
7810604SN/A     int in;
7910604SN/A} anon_union;
8010604SN/A
810SN/Aenum colors {
829056SN/A	RED,
839056SN/A	GREEN,
840SN/A	BLUE
859056SN/A} new_enum;
869056SN/A
870SN/A
889056SN/Aint *pointer;
899056SN/A
902050SN/ABEGIN
919056SN/A{
929056SN/A	printf("sizeof (new_char): %d\n", sizeof (new_char));
930SN/A	printf("sizeof (new_short): %d\n", sizeof (new_short));
949056SN/A	printf("sizeof (new_int): %d\n", sizeof (new_int));
959056SN/A	printf("sizeof (new_long): %d\n", sizeof (new_long));
968462SN/A	printf("sizeof (new_long_long): %d\n", sizeof (new_long_long));
979056SN/A	printf("sizeof (new_int8): %d\n", sizeof (new_int8));
989056SN/A	printf("sizeof (new_int16): %d\n", sizeof (new_int16));
998462SN/A	printf("sizeof (new_int32): %d\n", sizeof (new_int32));
1009056SN/A	printf("sizeof (new_int64): %d\n", sizeof (new_int64));
1019056SN/A	printf("sizeof (pointer): %d\n", sizeof (pointer));
1020SN/A	printf("sizeof (intptr_t): %d\n", sizeof (intptr_t));
1039056SN/A	printf("sizeof (new_struct): %d\n", sizeof (new_struct));
1049056SN/A	printf("sizeof (anon_struct): %d\n", sizeof (anon_struct));
1050SN/A	printf("sizeof (new_union): %d\n", sizeof (new_union));
1069056SN/A	printf("sizeof (anon_union): %d\n", sizeof (anon_union));
1079056SN/A	printf("sizeof (new_enum): %d\n", sizeof (new_enum));
1080SN/A	exit(0);
1099056SN/A}
1109056SN/A
1112061SN/AEND
1129056SN/A/(1 != sizeof (new_char)) || (2 != sizeof (new_short)) ||
1139056SN/A    (4 != sizeof (new_int)) ||
11410604SN/A    ((4 != sizeof (new_long)) && (8 != sizeof (new_long))) ||
11510604SN/A    (8 != sizeof (new_long_long)) ||
11610604SN/A    (1 != sizeof (new_int8)) || (2 != sizeof (new_int16)) ||
1170SN/A    (4 != sizeof (new_int32)) || (8 != sizeof (new_int64)) ||
1189056SN/A    (sizeof (pointer) != sizeof (new_intptr)) || (8 != sizeof (new_struct)) ||
1199056SN/A    (4 != sizeof (new_union)) || (4 != sizeof (new_enum))/
1200SN/A{
1219056SN/A	exit(1);
1229056SN/A}
1230SN/A