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: sizeof returns the size in bytes of any D expression or data 31 * type. 32 * 33 * SECTION: Structs and Unions/Member Sizes and Offsets 34 */ 35 #pragma D option quiet 36 37 char new_char; 38 short new_short; 39 int new_int; 40 long new_long; 41 long long new_long_long; 42 int8_t new_int8; 43 int16_t new_int16; 44 int32_t new_int32; 45 int64_t new_int64; 46 intptr_t new_intptr; 47 uint8_t new_uint8; 48 uint16_t new_uint16; 49 uint32_t new_uint32; 50 uint64_t new_uint64; 51 uintptr_t new_uintptr; 52 53 /* 54 float new_float; 55 double new_double; 56 long double new_long_double; 57 58 string new_string; 59 */ 60 61 struct record { 62 char ch; 63 int in; 64 } new_struct; 65 66 struct { 67 char ch; 68 int in; 69 } anon_struct; 70 71 union record { 72 char ch; 73 int in; 74 } new_union; 75 76 union { 77 char ch; 78 int in; 79 } anon_union; 80 81 enum colors { 82 RED, 83 GREEN, 84 BLUE 85 } new_enum; 86 87 88 int *pointer; 89 90 BEGIN 91 { 92 printf("sizeof (new_char): %d\n", sizeof (new_char)); 93 printf("sizeof (new_short): %d\n", sizeof (new_short)); 94 printf("sizeof (new_int): %d\n", sizeof (new_int)); 95 printf("sizeof (new_long): %d\n", sizeof (new_long)); 96 printf("sizeof (new_long_long): %d\n", sizeof (new_long_long)); 97 printf("sizeof (new_int8): %d\n", sizeof (new_int8)); 98 printf("sizeof (new_int16): %d\n", sizeof (new_int16)); 99 printf("sizeof (new_int32): %d\n", sizeof (new_int32)); 100 printf("sizeof (new_int64): %d\n", sizeof (new_int64)); 101 printf("sizeof (pointer): %d\n", sizeof (pointer)); 102 printf("sizeof (intptr_t): %d\n", sizeof (intptr_t)); 103 printf("sizeof (new_struct): %d\n", sizeof (new_struct)); 104 printf("sizeof (anon_struct): %d\n", sizeof (anon_struct)); 105 printf("sizeof (new_union): %d\n", sizeof (new_union)); 106 printf("sizeof (anon_union): %d\n", sizeof (anon_union)); 107 printf("sizeof (new_enum): %d\n", sizeof (new_enum)); 108 exit(0); 109 } 110 111 END 112 /(1 != sizeof (new_char)) || (2 != sizeof (new_short)) || 113 (4 != sizeof (new_int)) || 114 ((4 != sizeof (new_long)) && (8 != sizeof (new_long))) || 115 (8 != sizeof (new_long_long)) || 116 (1 != sizeof (new_int8)) || (2 != sizeof (new_int16)) || 117 (4 != sizeof (new_int32)) || (8 != sizeof (new_int64)) || 118 (sizeof (pointer) != sizeof (new_intptr)) || (8 != sizeof (new_struct)) || 119 (4 != sizeof (new_union)) || (4 != sizeof (new_enum))/ 120 { 121 exit(1); 122 } 123