Boost logo

Boost :

Subject: Re: [boost] [Boost.Pool] TR1?
From: Phil Bouchard (philippe_at_[hidden])
Date: 2011-04-12 21:17:39


On 4/12/2011 3:41 PM, Nevin Liber wrote:
>
> 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.

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.

-Phil


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