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