Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Feb 2006 23:02:11 +0100
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= <des@des.no>
Cc:        arch@FreeBSD.org, Stefan Farfeleder <stefanf@FreeBSD.org>
Subject:   Re: [releng_6 tinderbox] failure on sparc64/sparc64
Message-ID:  <20060205220211.GA5151@falcon.midgard.homeip.net>
In-Reply-To: <867j89n71d.fsf@xps.des.no>
References:  <20060204211357.GD7604@ip.net.ua> <20060204.143353.109955782.imp@bsdimp.com> <86fymyn5il.fsf@xps.des.no> <20060204.155856.39766510.imp@bsdimp.com> <20060205084813.GN21806@wombat.fafoe.narf.at> <867j89n71d.fsf@xps.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Feb 05, 2006 at 04:45:34PM +0100, Dag-Erling Sm=F8rgrav wrote:
> Stefan Farfeleder <stefanf@FreeBSD.org> 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 uint32_t.
> > > It used to cast directly, but that isn't allowed.  So, I've passed
> > > the cast through a (void *).  Is that allowed?  Eg:
> > >=20
> > > 	struct foo foo;
> > > 	((uint32_t *)(void *)&foo)[3] =3D 12;
> > >=20
> > > is that OK?
> > I'm afraid that only silences the warning without solving the underlying
> > problem.  I don't think there's a Standard conforming way to treat a
> > struct foo as an uint32_t array.
>=20
> 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 casting
pointers.

In general, if you have an object of type X, then the only ways it can be
accessed is either as an object of type X, or as an array of [unsigned]
char. =20


--=20
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060205220211.GA5151>