Boost logo

Boost :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2004-09-26 19:25:14


At Sunday 2004-09-26 02:19, you wrote:
> >From: "Victor A. Wagner Jr."
>
> > At Saturday 2004-09-18 03:44, Terje Slettebø wrote:
> >
> > >Even for + and -, there are differences, such as that you can subtract
>two
> > >pointers, but not add them.
> >
> > The erroneous assumption that this is true is something that has bothered
> > me for some time (and indeed I have worked on systems where it simply
>isn't
> > true, that the result of a+b would be useful even if both were
> > pointers). In an abstract sense it's not true on any system.
> >
> > Consider:
> >
> > T* a;
> > T* b;
> > .... get them assigned meaningfully to something in a sequence "container"
> >
> > The midpoint between them is (this is legal using your constraints):
> >
> > a + (b-a)/2
> >
> > 1st year algebra teaches us that this is equivalent to:
> >
> > (a+b)/2
>
>While this is interesting (and I understand it was not meant to pick on me
>in particular, as you said, and it wouldn't really make any sense, as Dave
>Abrahams pointed out), my point was strictly about what is legal _C++_, and
>the above is not legal C++, which I think you will agree with:
>
>"5.7 Additive operators
>[...]
>For addition, either both operands shall have arithmetic or enumeration
>type, or one operand shall be a
>pointer to a completely defined object type and the other shall have
>integral or enumeration type."
>
>The context was detecting addability, and if the trait had reported "yes"
>for pointers, it would have caused errors elsewhere.
>
>You might also argue that the language should allow the expression above,
>but that's a different discussion.

yes... I was trying to catch up on EMail while waiting for the regression
test to fail for mingw and just responded. It's a different discussion,
and yes, I believe the language is 'in error'.

> > I'll also note, in passing, that for integers the two are equivalent also,
> > but very few compilers will generate code to guarantee the correct result
> > if you attempt to calculate (a+b)/2 which _does_ exist on every
>computer
> > out there.
>
>With "correct result", I guess you mean the possibility of overflow in this
>expression, compared to the other form.

either form can overflow, (different circumstances, of course) therefore
the simple "average two things" just isn't all that easy in C++ (or C...or
any other HLL I'm aware of)

>Regards,
>
>Terje
>
>_______________________________________________
>Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
               "There oughta be a law"


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