C style peeve and knowing the rules

Guy Greenwald ggg at sunquest.UUCP
Tue Mar 27 02:00:53 AEST 1990


In article <894 at dino.cs.iastate.edu>, hascall at cs.iastate.edu (John Hascall) writes:
> 
>    Operator precedence and associativity in C is quite complicated
>    and somewhat non-intuitive.  A few well-placed parentheses can
>    go a long way toward promoting readability and understanding,
>    even if they are not strictly necessary.[1]

For once, I agree with Robert J. Drabek. If you read his article carefully,
you'll see he's making a pedagogic point. A student who is required to use
the minimum number of parentheses will have to understand C's precedence
rules. After the student leaves his class, he's on his own, but as a 
teacher, Robert will have done his job.

As for the egregious

      a /= b ? c << 3 & g || f ? e || 2 + ++d & ~c : w : z;

the programmer should have broken it up into a separate series of simpler
expressions.

      a /= (b ? (
                  (((c << 3) & g) || f) ? (
                                            (e || ((2 + ++d) & ~c)) :
                                            w
                                          ) :
                  z
                )
           );

is not much of an improvement, in my opinion.



More information about the Comp.lang.c mailing list