9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER START
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * The contents of this file are subject to the terms of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Common Development and Distribution License (the "License").
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You may not use this file except in compliance with the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * or http://www.opensolaris.org/os/licensing.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * See the License for the specific language governing permissions
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * and limitations under the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * When distributing Covered Code, include this CDDL HEADER in each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * If applicable, add the following below this CDDL HEADER, with the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * fields enclosed by brackets "[]" replaced with your own identifying
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * information: Portions Copyright [yyyy] [name of copyright owner]
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER END
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Use is subject to license terms.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#pragma ident "%Z%%M% %I% %E% SMI"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * ASSERTION: offsetof can be used anywhere in a D program that an integer
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * constant can be used.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * SECTION: Structs and Unions/Member Sizes and Offsets
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * NOTES:
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#pragma D option quiet
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahltypedef struct record {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl char c;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl int x;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl int y;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl} record_t;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlBEGIN
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl add = offsetof(record_t, c) + offsetof(record_t, x) +
9512fe850e98fdd448c638ca63fdd92a8a510255ahl offsetof(record_t, y);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl sub = offsetof(record_t, y) - offsetof(record_t, x);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl mul = offsetof(record_t, x) * offsetof(record_t, c);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl div = offsetof(record_t, y) / offsetof(record_t, x);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("offsetof(record_t, c) = %d\n", offsetof(record_t, c));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("offsetof(record_t, x) = %d\n", offsetof(record_t, x));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("offsetof(record_t, y) = %d\n", offsetof(record_t, y));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("Addition of offsets (c+x+y)= %d\n", add);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("Subtraction of offsets (y-x)= %d\n", sub);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("Multiplication of offsets (x*c) = %d\n", mul);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl printf("Division of offsets (y/x) = %d\n", div);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(0);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahlEND
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/(8 != offsetof(record_t, y)) || (4 != offsetof(record_t, x)) ||
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (0 != offsetof(record_t, c)) || (12 != add) || (4 != sub) || (0 != mul)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl || (2 != div)/
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(1);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}