Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4da76eba$1@news.x-privat.org> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | Phil Bouchard <phil@fornux.com> |
| Subject | Re: To standardize Boost.Pool |
| Organization | X-Privat.Org NNTP Server - http://www.x-privat.org |
| References | <4da38cde@news.x-privat.org> <4da63271@news.x-privat.org> |
| Date | 2011-04-14 17:18 -0600 |
On 4/14/2011 12:10 PM, Phil Bouchard wrote:
>
> is_from() actually invokes undefined behavior if its parameter is a
> pointer referring to an element outside of the pool according to 5.7.6.
> If the pointer was to be casted to the largest integer type available
> on the system then a range check would be valid for that system. For
> example:
>
> bool is_from(const char* p)
> {
> return reinterpret_cast<long>(buffer)<= reinterpret_cast<long>(p)&&
> reinterpret_cast<long>(p)< reinterpret_cast<long>(buffer + sizeof(buffer));
> }
>
> It's "implementation defined" but perhaps a reinterpret_cast of a
> pointer to a long integer could be guaranteed to be valid by the
> standards, long being the greatest integer available on a system.
>
It turns out the C standard defines intptr_t to be the same size as a
pointer (7.18.1.4). The following would consequently be perfectly portable:
bool is_from(const char* p)
{
return reinterpret_cast<intptr_t>(buffer)<=
reinterpret_cast<intptr_t>(p)&&
reinterpret_cast<intptr_t>(p)< reinterpret_cast<intptr_t>(buffer +
sizeof(buffer));
}
Regards,
-Phil
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-12 13:10 -0600
Re: To standardize Boost.Pool Phil Bouchard<phil@fornux.com> - 2011-04-14 13:10 -0600
Re: To standardize Boost.Pool Phil Bouchard <phil@fornux.com> - 2011-04-14 17:18 -0600
Re: To standardize Boost.Pool "Bo Persson" <bop@gmb.dk> - 2011-04-17 01:33 -0600
csiph-web