
On 4/13/2011 3:45 PM, Phil Bouchard wrote:
On 4/13/2011 3:26 PM, Dave Abrahams wrote:
Stop, stop, seriously. That's not a bug, and your code isn't guaranteed to produce any particular result either, portably. reinterpret_cast has unspecified or implementation-defined results (I forget which) in this case.
It's implementation defined.
Please apologize my tenacity but the C standard defines intptr_t to be the same size as a pointer. This is defined in "cstdint" so consequently we could use: struct Silly { bool is_from(const char* p) { return !std::less<intptr_t>()(reinterpret_cast<intptr_t>(p), reinterpret_cast<intptr_t>(buffer)) && std::less<intptr_t>()(reinterpret_cast<intptr_t>(p), reinterpret_cast<intptr_t>(buffer + sizeof(buffer))); } char buffer[1024]; }; -Phil