Why no @ or $ operator in C++?

J

James Kanze

Le vendredi 18 avril 2014 23:47:57 UTC+1, Peter a écrit :
I didn't mean to invent a new operator, I just wondered
why none of the two symbols mentioned by me were used
to denote one of already existing operators.
C and C++ are known for being context sensitive which
is one of the reasons why it's so hard to write a compiler
for them.

But there's nothing in the operators which is context sensitive,
or at least, which can't be simply resolved. The real issues
are declaration syntax.
With two extra symbols this context
sensitivity could at least have been reduced.
Example: & currently means three different things
in C++: a reference, an "address of" operator and "bit and".
If there were two symbols left, why weren't they used
by language creators to reduce some of this ambiguity
in favor of simpler grammar? An "address of" operator
could be, for example, @ (as someone noticed, it is
in Pascal). Perhaps $ could have been used to represent
a C++11 rvalue reference. Instead it was decided to reuse
the good old &&.

One of the big issues is template parameters and arguments; the
fact that < and > were used does lead to a number of ambiguities
(and more than one person did suggest new tokens, although
without using any new characters). You'd want some sort of
tokens with an open/close pairing, but "($" and "$)", for
example, would have made life a lot simpler. For that matter,
postfixing (or prefixing) a symbol with a "$" to indicate that
it is dependent would be a lot better than the current system,
with a lot of complicated rules that you have to second guess,
and which are difficult to explain to beginners.

One of the problems with $, of course, is that it is a frequent
extension to accept it in symbols.
 
J

James Kanze

Le samedi 19 avril 2014 20:33:28 UTC+1, David Harmon a écrit :
You've never seen APL then.

I said "reasonably". APL is a good example of why you don't
want too many one character operators.

Now that I think of it, one of the real problems with C is (or
was) that it used too many characters. I've had to write C with
keyboards which had no [, ], {, }, | nor #. (And believe me,
trigraphs aren't really a usable solution.)
 
S

Stefan Ram

Circa 1982, I used some command shell on BSD 2.3, I doubt I ever
knew what it was called. (It may have been written in-house.)
Anyway, @ was the "kill line" character by default (like ^U in csh
these days).

I think one can still get this behavior today (under some
implementations and shells) using

stty intr \^?
stty erase \#
stty kill @

(not tested). Try this, and you will feel young again, as if
it was 1982!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,095
Messages
2,570,616
Members
47,232
Latest member
helpplease!

Latest Threads

Top