Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2006-07-09 07:27:59


On 7/7/06 5:31 PM, "Dean Michael Berris" <mikhailberis_at_[hidden]> wrote:

> Since a pointer is basically a primitive type which you can manipulate
> like an integral type, it opens up a can of worms you don't want to
> deal with -- and will only make the code a lot easier to get wrong.
> Since you can manipulate pointers like int's, the following operations
> will be valid:
>
> exception_info * x = get_exception_info(e);
> x++;
> ++x;
>
> But if you're using references, you give a cleaner and more definite
> handle to your data:
>
> exception_info & info (get_exception_info(e));
> info ++; // won't work, unless operator++ is defined for exception_info

As another poster said, you can take the address of "info" and then repeat
the same stupid pointer tricks. The programmer's advice, "guard against
Murphy, not Machiavelli," applies here. Your pointer flaw isn't because of
this library's API, it's a general problem in C++. That's because all
pointers define the ++ and -- operators for use with array segments,
ignoring the fact that a pointer can be indistinctively used for single
objects. In other words: "if you see this code, fire the programmer".

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

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