X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.glorb.com!news2.glorb.com!border3.nntp.dca.giganews.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 NNTP-Posting-Date: Thu, 14 Apr 2011 17:20:08 -0500 Return-Path: Sender: std-cpp-request@vandevoorde.com Approved: austern@google.com Message-ID: <4da76eba$1@news.x-privat.org> Newsgroups: comp.std.c++ From: Phil Bouchard 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> Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Original-Date: Thu, 14 Apr 2011 15:01:22 -0700 X-Submission-Address: std-c++-submit@vandevoorde.com To: undisclosed-recipients:; Date: Thu, 14 Apr 2011 17:18:28 CST Lines: 43 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-ytfRmT1of5Ig/7us0kv7XqJ4kHW93lxMNSCa9q3albgsXcYPvMbWOfs1+ziLebTBvJtgMhgcJMJgjkB!53RTfLXcnxxKcCugW975EzLAJ2VxA4q/D9NhbsJiYXnFPZLr3U3Qfg== 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: 2697 Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:105 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(buffer)<= reinterpret_cast(p)&& > reinterpret_cast(p)< reinterpret_cast(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(buffer)<= reinterpret_cast(p)&& reinterpret_cast(p)< reinterpret_cast(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 ]