Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #108

Re: To standardize Boost.Pool

NNTP-Posting-Date Sun, 17 Apr 2011 01:40:05 -0500
Return-Path <cppmods@mcgurn.dreamhost.com>
Sender std-cpp-request@vandevoorde.com
Approved james.dennett@gmail.com
Message-ID <90t6p2FgvoU1@mid.individual.net> (permalink)
Newsgroups comp.std.c++
From "Bo Persson" <bop@gmb.dk>
Subject Re: To standardize Boost.Pool
Organization unknown
References <4da38cde@news.x-privat.org> <4da63271@news.x-privat.org> <4da76eba$1@news.x-privat.org>
X-Original-Date Sat, 16 Apr 2011 11:45:21 +0200
X-Submission-Address std-c++-submit@vandevoorde.com
To undisclosed-recipients:;
Date Sun, 17 Apr 2011 01:33:41 CST
Lines 53
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-Kmc2LOvRJwM2ahbusvtTYKs2WIOQ9QfjwnEZY+AmcPn3RpfEeFQAQVsjeYNF/O59f6m4tYYNaMj1xIA!ip1uhQhkWFHojruF4FEBWxD3mmw03fouPbCWdXTEnCcoq7v12Fujf9b0bQ==
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2892
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.std.c++:108

Show key headers only | View raw


Phil Bouchard wrote:
> 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));
> }
>
>

For some definition of "perfectly", yes.

The typedef is optional, because there is no requirement for an
implementation to actually have an integer type wide enough to hold a
pointer.


Bo Persson



--
[ 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 | NextPrevious in thread | Find similar


Thread

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