J
john
Keith said:john said:Eric Sosman wrote: [...]On 5/12/2010 6:44 PM, john wrote:
[... arithmetic operators with two pointer operands ...] For
example, if / was average then this would lead to simpler code like
johns_search(int *first, int *last)
{
int *mid = first / last;
... [snip]
In "fairy C" you can define anything any way you like, of course,
but I can't see any mnemonic connection between the two expressions.
Perhaps if you suggested `(first + last) / 2' a case could be made,
but `first / last'? Why should that be understood as "the midpoint
between first and last?" It's not, for example, how you calculate the
midpoint between two ordinary numbers: 1/10 is 0 or 0.1 depending on
types, but the midpoint between 1 and 10 is nowhere near either. To my
eye, your suggestion seems arbitrary -- which may just mean I'm too
dense to discern the underlying logic, but sqrt(first * last) looks
equally sensible to me.
I think you are being deliberately obtuse here.
The point is that at present, if p and q are pointers, then p / q has
no meaning, so you lose nothing and gain some brevity by giving it a
meaning. I chose as an example defining "p / q" to be the average of p
and q, i.e. q - (q - p) / 2. You could instead define p & q to be the
average and p / q to be the minimum of p and q - whatever you wanted,
or whatever the standards body finds most mnemonic if you like.
As long as it was standardized, everyone would be on the same page.
That's (at least) the second time today you've accused someone of being
"deliberately obtuse" because they disagreed with you.
Yes, your proposal of adding multiple built-in overloaded operators for
pointers would be compatible with the current language; it wouldn't
break existing code. But using "/" for pointer average would be
confusing and would, in my opinion not provide enough benefit to justify
the costs. It's used rarely enough that, even if it were standardized,
typical programmers would likely not recognize it. And even if it were
added to the C201X standard, we'd have to wait at least a decade before
we could confidently write code that depends on it.
I'm disappointed that people here don't appear willing to engage
positively with my suggestions for improving the language. I know C is a
"traditional" language mainly favored by older, perhaps more conservative
programmers, but it would be a shame if it faded into obscurity because
of the reluctance of its practitioners to embrace new features.
Just my $0.02.