Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162634

Re: C precedence - relative comparisons before equality operators

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: C precedence - relative comparisons before equality operators
Date 2021-09-06 13:01 +0200
Organization A noiseless patient Spider
Message-ID <sh4sem$35j$1@dont-email.me> (permalink)
References (1 earlier) <sh38om$1nc6m$1@news.xmission.com> <Q_aZI.46522$F26.22819@fx44.iad> <sh3io6$pfh$1@dont-email.me> <sh4f6i$bh7$1@dont-email.me> <sh4pe3$fue$1@dont-email.me>

Show all headers | View raw


On 06/09/2021 12:10, Bart wrote:
> On 06/09/2021 08:15, David Brown wrote:
>> On 06/09/2021 01:09, Bart wrote:
>>> On 05/09/2021 22:52, Richard Damon wrote:
>>>
>>>> Also, it puts less operators at any give level of the grammer which
>>>> might be useful. You end up with more levels of grammer, but each
>>>> one is
>>>> simpler.
>>
>> I think that is a very likely reason.
>>
>>>
>>> I dispute it's that useful; but it is certainly harder to remember all
>>> the different levels. You can also can't assume that everyone will know
>>> them as well as you.
>>
>> You don't need to remember all the different levels.  You need to
>> remember the common ones, and they are all pretty obvious - no one is
>> going to be in doubt about the meaning of "a = b * c + d;".
>>
>> Beyond that, you can always add parenthesis or split the expression into
>> sub-expressions - whatever makes the code clearer and more maintainable.
>>
>> You might need to be able to understand other people's code written with
>> fewer parenthesis than you might personally like, but usually it's clear
>> what they meant unless they were deliberately writing smart-arse code.
> 
> If everybody was trusted to do that, or expected to, then what was the
> point of having so many precedence levels?!

As has been discussed, it simplifies the grammar and language
specification if operators are divided into groups based on the type of
operands allowed, and then having these groups given different precedence.

> 
> (How many can list the precedence levels of &, | and ^, or can explain
> why any one is ranked higher than another?)

For "and" and "or" operations, it is standard mathematical convention to
treat "and" as higher precedence than "or".  The operations are even
written as "." and "+" in many cases.  Where exclusive or fits in is a
different matter.

> 
> C has twice as many as I do for the same set of operators.
> 

Do you actually have a formal grammar and language specification?

> Specifically, I parse a<<8 + b the same way as a*256 + b, for obvious
> reasons. In C, one is a<<(8+b), the other is (a*256)+b.
> 

I assume you are thinking of shifts as a kind of multiplication or
division, and therefore it should be a higher precedence than addition
and subtraction.  Looking at things purely objectively, I'd be inclined
to agree.  I am generous with parenthesis when using shift operators.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

C precedence - relative comparisons before equality operators James Harris <james.harris.1@gmail.com> - 2021-09-05 18:49 +0100
  Re: C precedence - relative comparisons before equality operators Siri Cruise <chine.bleu@yahoo.com> - 2021-09-05 13:11 -0700
  Re: C precedence - relative comparisons before equality operators Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-05 21:12 +0100
    Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 09:09 +0200
  Re: C precedence - relative comparisons before equality operators gazelle@shell.xmission.com (Kenny McCormack) - 2021-09-05 20:19 +0000
    Re: C precedence - relative comparisons before equality operators Richard Damon <Richard@Damon-Family.org> - 2021-09-05 17:52 -0400
      Re: C precedence - relative comparisons before equality operators Bart <bc@freeuk.com> - 2021-09-06 00:09 +0100
        Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 09:15 +0200
          Re: C precedence - relative comparisons before equality operators Bart <bc@freeuk.com> - 2021-09-06 11:10 +0100
            Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 13:01 +0200
              Re: C precedence - relative comparisons before equality operators Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-09-06 04:20 -0700
    Re: C precedence - relative comparisons before equality operators John Bode <jfbode1029@gmail.com> - 2021-09-07 09:27 -0500
      Re: C precedence - relative comparisons before equality operators Bart <bc@freeuk.com> - 2021-09-08 00:20 +0100
        Re: C precedence - relative comparisons before equality operators John Bode <jfbode1029@gmail.com> - 2021-09-08 14:18 -0500
  Re: C precedence - relative comparisons before equality operators Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-06 02:01 +0100
    Re: C precedence - relative comparisons before equality operators James Harris <james.harris.1@gmail.com> - 2021-09-06 09:39 +0100
      Re: C precedence - relative comparisons before equality operators Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-06 10:46 +0100
        Re: C precedence - relative comparisons before equality operators Richard Damon <Richard@Damon-Family.org> - 2021-09-06 10:09 -0400
          Re: C precedence - relative comparisons before equality operators Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-06 16:05 +0100
  Re: C precedence - relative comparisons before equality operators James Harris <james.harris.1@gmail.com> - 2021-09-06 09:27 +0100
    Re: C precedence - relative comparisons before equality operators James Harris <james.harris.1@gmail.com> - 2021-09-06 12:18 +0100
      Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 13:44 +0200
        Re: C precedence - relative comparisons before equality operators James Harris <james.harris.1@gmail.com> - 2021-09-06 13:38 +0100
          Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 18:12 +0200
        Re: C precedence - relative comparisons before equality operators tth <tth@none.invalid> - 2021-09-06 18:20 +0200
          Re: C precedence - relative comparisons before equality operators David Brown <david.brown@hesbynett.no> - 2021-09-06 23:40 +0200
      Re: C precedence - relative comparisons before equality operators Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-06 17:20 -0700
    Re: C precedence - relative comparisons before equality operators Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-09-06 13:44 +0100
    Re: C precedence - relative comparisons before equality operators Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-06 17:23 -0700
  Re: C precedence - relative comparisons before equality operators James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-06 23:07 -0400

csiph-web