This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: >, >>, and "tee" operators


On Tue, 30 Jul 2002 23:25:25 -0400, Andrew Cagney
<ac131313@ges.redhat.com> said:

>> So in other words, I'd like to stick with 
>> 
>>> >  redirect [-a[ppend]] FILE [COMMAND]
>>> >  log [-a[ppend]] FILE [COMMAND]

> Don't forget that prefix `-' and `--' are valid C operators.  You
> can't tell the difference between the above and a valid C
> expressions.  I think that rules `-...' out.

It makes '-...' undesirable, but I don't think it rules it out.  Yes,
there are situations where what had previously been a legitimate print
statement now becomes either a syntax error or, worse yet, remains
legitimate but with a different meaning.  But I doubt they are all
_that_ common, and there is an easy workaround once you're aware of
this problem, namely enclosing your expression in parentheses.

The reason why I don't think they're all that common is that I don't
think that it's all that common to want to print the value of an
expression starting with a unary minus.  I don't think I'd do that
very frequently in everyday interactive use: even if the value that I
happen to care about is -something, I'd probably just do 'p something'
and negate the answer mentally.  I find it easier to imagine printing
an expression that begins with a unary minus if that print command is
run automatically when hitting a breakpoint, but even there I doubt it
would be too uncommon.

And, furthermore, it only breaks code where the next character after
the unary - is one of the formatting symbols and the character after
that is whitespace.  (So the fact that '--' is a valid C operator
isn't so relevant, because '-' isn't a formatting character.  Good
thing, too, because I print expressions starting with '--' more often
than ones starting just with '-'.)  Unfortunately, some of the
formatting symbols are common variable names - probably '-x' would be
the most common clash - but even so I'm sure that, the vast majority
of the time an expression starts with a unary minus, the unary minus
is unambiguously part of the expression.

And it seems to me that it isn't so big a problem when previously
valid print statements become syntax errors: in those situations, the
user at least is aware that something's wrong, and can insert
parentheses to solve the problem.  Situations where previously valid
print statements remain valid but have their meaning changed are more
problematic; but those are even more rare.  Sure, there are some
examples - 'p -x - 3' is one (though 'p -x-3' isn't, or 'p (-x) - 3')
- but they're not at all common.

So I think that, if this syntax is changed, the fact that expressions
could start with unary minus signs is going to cause much less
grumbling from users than the fact that, once the old p/x syntax gets
obsoleted, they'll have to convert over to typing p -x instead.

David Carlton
carlton@math.stanford.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]