Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-04-19 22:15:39


On Sat, Apr 19, 2008 at 8:38 PM, Bo Persson <bop_at_[hidden]> wrote:
> Giovanni Piero Deretta wrote:
> > On Sat, Apr 19, 2008 at 5:30 PM, Bo Persson <bop_at_[hidden]> wrote:
> >>
> >> Giovanni Piero Deretta wrote:
> >> > On Fri, Apr 18, 2008 at 5:34 PM, Matt Doyle <mdoyle_at_[hidden]>
> >> > wrote:
> >> >>> [mailto:boost-bounces_at_[hidden]] On Behalf Of Giovanni
> >> >> > Piero Deretta
> >> >> >
>
> >> >> > Changing:
> >> >> >
> >> >> > inline std::size_t float_hash_impl(float v)
> >> >> > {
> >> >> > boost::uint32_t* ptr = (boost::uint32_t*)&v;
> >> >> > std::size_t seed = *ptr;
> >> >> > return seed;
> >> >> > }
> >> >> >
> >> >> > to
> >> >> >
> >> >> > inline std::size_t float_hash_impl(float v)
> >> >> > {
> >> >> > std::size_t seed;
> >> >> > std::memcpy(&x, &v, sizeof(x));
> >> >> > return seed;
> >> >> > }
> >> >> >
> >> >>
> >> >> /x/seed/ ??
> >> >>
> >> >
> >> > Yes, of course :)
> >>
> >>
> >> And also assuming that sizeof(seed) ==sizeof(float) ?
> >>
> > Yes, but, as the code is only compiled in when under X86, you can
> > safely assume that.
>
> Ok, I though it was used for x86_64 as well, but I might be wrong.
>

If I have read the preprocessor conditionals correctly, oddly enough
it will enabled only on cygwin/x86. In theory the same code should
work for all gccs (it should work for all x86 compilers in fact).

And yes, it will break for x86_64 cpus, where size_t is 64 bits, but
that is easily fixed.

-- 
gpd

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk