From owner-freebsd-arch@FreeBSD.ORG Mon Feb 13 07:25:42 2006 Return-Path: X-Original-To: arch@freebsd.org Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 45F8516A420; Mon, 13 Feb 2006 07:25:42 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id D280F43D45; Mon, 13 Feb 2006 07:25:41 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id k1D7NAqN031556; Mon, 13 Feb 2006 00:23:17 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Mon, 13 Feb 2006 00:23:10 -0700 (MST) Message-Id: <20060213.002310.125802352.imp@bsdimp.com> To: ertr1013@student.uu.se From: "M. Warner Losh" In-Reply-To: <20060205220211.GA5151@falcon.midgard.homeip.net> References: <20060205084813.GN21806@wombat.fafoe.narf.at> <867j89n71d.fsf@xps.des.no> <20060205220211.GA5151@falcon.midgard.homeip.net> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Mon, 13 Feb 2006 00:23:18 -0700 (MST) Cc: des@des.no, stefanf@freebsd.org, arch@freebsd.org Subject: Re: [releng_6 tinderbox] failure on sparc64/sparc64 X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Feb 2006 07:25:42 -0000 In message: <20060205220211.GA5151@falcon.midgard.homeip.net> Erik Trulsson writes: : On Sun, Feb 05, 2006 at 04:45:34PM +0100, Dag-Erling Sm=F8rgrav wrote= : : > Stefan Farfeleder writes: : > > On Sat, Feb 04, 2006 at 03:58:56PM -0700, M. Warner Losh wrote: : > > > This driver wants to access these structures as arrays of uint3= 2_t. : > > > It used to cast directly, but that isn't allowed. So, I've pas= sed : > > > the cast through a (void *). Is that allowed? Eg: : > > > = : > > > struct foo foo; : > > > ((uint32_t *)(void *)&foo)[3] =3D 12; : > > > = : > > > is that OK? : > > I'm afraid that only silences the warning without solving the und= erlying : > > problem. I don't think there's a Standard conforming way to trea= t a : > > struct foo as an uint32_t array. : > = : > A union should do the trick. : = : No, it will not. If you have a struct foo and try to access it as an= array : of int, the program will have unspecified (and maybe even undefined) : behaviour. It does not matter if you do it with a union or by castin= g : pointers. : = : In general, if you have an object of type X, then the only ways it ca= n be : accessed is either as an object of type X, or as an array of [unsigne= d] : char. = So the proper fix for the above code is: struct foo foo; uint32_t value[sizeof(foo) / sizeof(uint32_t)]; memcpy(value, &foo); // write out value one 32-bit word at a time Is that right? Or at least 'proper' here means defined. Warner = =