|
Boost : |
Subject: Re: [boost] [Boost.Pool] TR1?
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-04-13 01:02:13
On Apr 12, 2011, at 9:18 PM, Phil Bouchard wrote:
> On 4/12/2011 6:52 PM, Nevin Liber wrote:
>> On 12 April 2011 20:17, Phil Bouchard<philippe_at_[hidden]> wrote:
>>
>>> Once again if is_from() was implemented the following way:
>>>
>>> bool is_from(const char* p)
>>> { return p - buffer> 0&& p - buffer< sizeof(buffer); }
>>>
>>> Then the undefined behaviors would seem to go away.
>>
>>
>> What makes you believe that? Read the section on pointer arithmetic in the
>> C99 standard.
>>
>> (Unless this comes back to being Boost related, we really ought to move this
>> discussion out of here.)
>
> 5.7.6 covers this issue already hahaha.
>
> It looks like the data, heap and stack pools in ::process will simply need to be contiguous.
5.7.6 starts out "When two pointers to elements of the same array object are subtracted, the result is the difference of the subscripts of the two array elements", and finishes with "Unless both pointers point to elements of the same array object, or one past the last element of the array object, the behavior is undefined."
So, if p points into buffer, then "p - buffer" is valid - but if it is not, then it is undefined behavior.
So, I have to agree with Nevin - you might as well write the routine like this:
bool is_from(const char* p) { return true; }
because it will return true for all cases where the behavior of your code is defined - and when the behavior is undefined, then who cares what it returns?
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk