Boost logo

Boost :

From: Rene Rivera (grafik666_at_[hidden])
Date: 2002-07-23 17:02:57


[2002-07-23] Craig Henderson wrote:

>>
>> There's a trick I use to get rid of the need for "extra" template
>parameters
>> that might be usefull here...
>>
>> template<typename Target, typename Source, typename E>
>> inline Target lexical_cast(Source arg, E& interpreter =
>> (*reinterpret_cast<E*>(0))
>> ...
>
>
>I'm not sure that dereferencing a null pointer in this way to create a
>reference this is a good idea. Not least, my test on MSVC does not compile:
>
> short &t = *(reinterpret_cast<short*>(0));
>
>generates an error
> error C2040: 't' : 'short &' differs in levels of indirection from
>'short'

Not usually a good idea unless you have tight control of it's use. It's too
bad MSVC chokes on it though :-(

>my g++ 2.95.3-5 on cygwin compiles it without error and runs, but as soon
as
>the variable t is accessed, it generates a Segmentation Fault - I guess an
>Access Violation alternative.

This is part of the tigh control, you would obviously have to check to
ensure you actually have an object... if (&t != 0)... etc.

-- grafik - Don't Assume Anything
-- rrivera_at_[hidden] - grafik_at_[hidden]
-- 102708583_at_icq - Grafik666_at_AIM - Grafik_at_[hidden]


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