Re: [Pull] Some documentation patches

From: Jan Engelhardt
Date: Tue Apr 01 2008 - 16:00:19 EST



On Monday 2008-03-31 16:31, Dmitri Vorobiev wrote:
@@ -107,8 +107,8 @@ complete. Here's the example version:

static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
- loff_t *spos = (loff_t *) v;
- *pos = ++(*spos);
+ loff_t *spos = v;
+ *pos = ++*spos;

Excuse me, what's the point in this change and the next one? IMO, removing
the explicit type cast makes the code less obvious.

Why should it be less obvious? Exactly left to the (loff_tÂ*) you
already have loff_tÂ*, so you know where you are going from v,
whose type is also obviously visible right in the line above.
Casts can hide errors. The cast is redundant, it does not
cover up a compiler warning. Even so, casts can hide programming
errors, as in http://jengelh.hopto.org/2007/0616-nocast.php .

Relying upon operator priorities instead of explicit
operator grouping using parentheses can confuse people, too.

In case of *a++ I would agree -- you would need to know whether * or
++ has the higher precedence (hint: ++ has). But in ++*a it does not
matter how much precedence either has, it always means the same.
Just like an arithmetic expression "x*-5".
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/