Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-08-04 08:44:03


On Fri, 4 Aug 2006 12:00:16 +0100, "Martin Bonner"
<martin.bonner_at_[hidden]> wrote:

>----Original Message----
>From: boost-bounces_at_[hidden]
>[mailto:boost-bounces_at_[hidden]] On Behalf Of Peter Dimov Sent:
>04 August 2006 11:39 To: boost_at_[hidden]
>Subject: Re: [boost] Portable signbit macro/function?
>
>> Johan Råde wrote:
>>
>>> I still find it hard to believe that the volatile are needed ;-)
>>
>> It is not.
>
>If volatile is not present, then you can't instantiate the template with T="volatile float" for example. (Similarly you need the "const" so that you can invoke with T="const float".)
>
>I suspect that for this application that doesn't matter, but that Gennaro was so used to using the safe form:
> reinterpret_cast<const volatile char*>(&s)
>to get at the bytes of an object in a template, that he just wrote it automatically.

Yes :-) And I didn't use boost::addressof because it uses char, not
unsigned char (there are endless debates here, especially after C99
has made some properties of signed char explicit; in any case you are
safe at home with unsigned; God knows where you are with plain char).

I should add that I didn't write a template, just something resembling
one :-) And the code was meant to throw an idea, not to be so
carefully analyzed (which is welcome, anyway).

It's important, too, that some care is taken to have the value in
memory, not in a register (think for instance of Intel's native
format); the latter may happen implicitly when passing the floating
point as argument. In any case, I just used "one" and "minus one", and
as local variables: passing a generic value opens a whole new can of
worms.

--
[ Gennaro Prota, C++ developer for hire ]

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