[releng_6 tinderbox] failure on sparc64/sparc64

Giorgos Keramidas keramida at ceid.upatras.gr
Mon Feb 13 00:23:49 PST 2006


On 2006-02-13 00:23, "M. Warner Losh" <imp at bsdimp.com> wrote:
> In message: <20060205220211.GA5151 at falcon.midgard.homeip.net>
>             Erik Trulsson <ertr1013 at student.uu.se> writes:
> : On Sun, Feb 05, 2006 at 04:45:34PM +0100, Dag-Erling Sm?rgrav wrote:
> : > Stefan Farfeleder <stefanf at 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:
> : > > >
> : > > > 	struct foo foo;
> : > > > 	((uint32_t *)(void *)&foo)[3] = 12;
> : > > >
> : > > > 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.
> : >
> : > 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.
>
> 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.

AFAIK, yes.



More information about the freebsd-arch mailing list