Boost logo

Boost :

Subject: Re: [boost] [Boost.Pool] TR1?
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-04-12 18:41:49


On 12 April 2011 17:01, Nevin Liber <nevin_at_[hidden]> wrote:

> On 12 April 2011 16:46, Phil Bouchard <philippe_at_[hidden]> wrote:
>
>> On 4/12/2011 10:15 AM, Nevin Liber wrote:
>>
>>>
>>> Only if it is implemented the way Steven described it. You cannot
>>> legally
>>> compare pointers using relationship operators (<,<=,>,>=) unless at least
>>> one is NULL, they are both pointing within the same object, or both
>>> pointing
>>> within the same array (or just past the end of the array). All other
>>> comparisons are undefined behavior. See 6.5.8 of the C99 standard for a
>>> much more precise definition.
>>>
>>
>> I understand but a memory page is in general aligned and therefore the
>> pointer difference (ptrdiff) of the beginning of the page with the location
>> of the object can be valid. In other words the memory page can be an array
>> of type T.
>
>
> I'm not saying that it won't accidentally work, but once you have undefined
> behavior, the compiler is free to do anything it wants.
>

To illustrate this, take the following code:

struct Silly
{
    bool is_from(const char* p)
    { return buffer <= p && p < buffer + sizeof(buffer); }

    char buffer[1024];
};

I believe that a compiler could legally optimize the body of Silly::is_from
to be:
 { return true; }

because in the defined behavior case it returns true, and the compiler can
do whatever it wants in the undefined behavior case.

As Dave pointed out, the Boost-related issue is that Bool.Pool has a
function relying on underfined behavior...

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

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