Boost logo

Boost :

Subject: Re: [boost] [Boost.Pool] TR1?
From: Phil Bouchard (philippe_at_[hidden])
Date: 2011-04-13 23:32:59


On 4/13/2011 3:45 PM, Phil Bouchard wrote:
> On 4/13/2011 3:26 PM, Dave Abrahams wrote:
>>
>> Stop, stop, seriously. That's not a bug, and your code isn't
>> guaranteed to produce any particular result either, portably.
>> reinterpret_cast has unspecified or implementation-defined results (I
>> forget which) in this case.
>
> It's implementation defined.

Please apologize my tenacity but the C standard defines intptr_t to be
the same size as a pointer. This is defined in "cstdint" so
consequently we could use:

struct Silly
{
    bool is_from(const char* p)
    {
       return !std::less<intptr_t>()(reinterpret_cast<intptr_t>(p),
reinterpret_cast<intptr_t>(buffer)) &&
               std::less<intptr_t>()(reinterpret_cast<intptr_t>(p),
reinterpret_cast<intptr_t>(buffer + sizeof(buffer)));
    }

    char buffer[1024];
};

-Phil


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