[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FYI: line nums in C++
From: |
Paul Eggert |
Subject: |
Re: FYI: line nums in C++ |
Date: |
20 Feb 2003 09:42:19 -0800 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 |
Akim Demaille <address@hidden> writes:
> > unsigned int l_ = rline_[n_];
> > YYCDEBUG << "Reducing via rule " << n_ - 1 << " (line " << l_ << "), ";
>
> Well, I am not convinced that this is more readable. In particular
> the cast here does look like a function call, and this functional
> style is more readable to my eyes than something more imperative.
It's no more imperative than the other style, as it merely gives a
name to a subexpression. That is commonly done even in purely
functional languages.
In C, another advantage of using the named subexpression is that it's
more likely to catch a programming error. If rline_[n_] happened to
be of pointer type, the above code must cause the compiler to generate
a diagnostic; this is not true of the static cast. The problem is
that casts are too strong; they convert too many different types to
the result type. Initializers are weaker, and are thus more likely to
catch coding errors. I suspect that similar results hold for C++.
It's no big deal, of course.