Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #162618 > unrolled thread
| Started by | James Harris <james.harris.1@gmail.com> |
|---|---|
| First post | 2021-09-05 18:49 +0100 |
| Last post | 2021-09-06 23:07 -0400 |
| Articles | 10 on this page of 30 — 12 participants |
Back to article view | Back to comp.lang.c
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
Page 2 of 2 — ← Prev page 1 [2]
| From | James Harris <james.harris.1@gmail.com> |
|---|---|
| Date | 2021-09-06 12:18 +0100 |
| Message-ID | <sh4tdj$8l2$1@dont-email.me> |
| In reply to | #162630 |
On 06/09/2021 09:27, James Harris wrote: > On 05/09/2021 23:29, Stefan Ram wrote: ... >> Kernighan/Ritchie wrote: >> >> |The == (equal to) and the != (not equal to) operators are >> |analogous to the relational operators except for their lower >> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have >> |the same truth-value.) > > Do you have a link to the source of that? No need to reply. I found it in A.7.10 of https://osm.hpi.de/bs/2019/material/The_C_Programming_Language.pdf -- James Harris
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-09-06 13:44 +0200 |
| Message-ID | <sh4uvj$jd3$1@dont-email.me> |
| In reply to | #162635 |
On 06/09/2021 13:18, James Harris wrote: > On 06/09/2021 09:27, James Harris wrote: >> On 05/09/2021 23:29, Stefan Ram wrote: > > ... > >>> Kernighan/Ritchie wrote: >>> >>> |The == (equal to) and the != (not equal to) operators are >>> |analogous to the relational operators except for their lower >>> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have >>> |the same truth-value.) >> >> Do you have a link to the source of that? > > No need to reply. I found it in A.7.10 of > Please do not post links to copyrighted books. I don't know if that link is legal or a copyright violation, but "some link I found with google" is certainly inappropriate. It is also long out of date - TCPL is historically interesting, and a fine example of good technical writing, but not necessarily an accurate reference of current C - it formed the basis of the C standard, but has not been updated with the standard. The current C standard is C17, with the last pre-certification draft available freely and legally from the WG14 themselves at: <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2176.pdf> C99, C11 and the latest draft of C2x are also available: <http://www.open-std.org/jtc1/sc22/wg14/www/projects> (You'll find the text in question in 6.5.8p8 and footnote 110).
[toc] | [prev] | [next] | [standalone]
| From | James Harris <james.harris.1@gmail.com> |
|---|---|
| Date | 2021-09-06 13:38 +0100 |
| Message-ID | <sh5247$aes$1@dont-email.me> |
| In reply to | #162637 |
On 06/09/2021 12:44, David Brown wrote: > On 06/09/2021 13:18, James Harris wrote: >> On 06/09/2021 09:27, James Harris wrote: >>> On 05/09/2021 23:29, Stefan Ram wrote: >> >> ... >> >>>> Kernighan/Ritchie wrote: >>>> >>>> |The == (equal to) and the != (not equal to) operators are >>>> |analogous to the relational operators except for their lower >>>> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have >>>> |the same truth-value.) >>> >>> Do you have a link to the source of that? >> >> No need to reply. I found it in A.7.10 of >> > > Please do not post links to copyrighted books. I don't know if that > link is legal or a copyright violation, but "some link I found with > google" is certainly inappropriate. Not so. The book is published on the website of the Hasso Plattner Institute in Germany. You can read about them at https://en.wikipedia.org/wiki/Hasso_Plattner_Institute I checked before posting the link that they were legitimate. As such, they have to take responsibility for what they publish and may well have (or, will likely have) permission to do so, especially if they have had the book on their website since 2019, as appears to be the case. > > It is also long out of date - TCPL is historically interesting, and a > fine example of good technical writing, but not necessarily an accurate > reference of current C - it formed the basis of the C standard, but has > not been updated with the standard. I was asking for the source of the quote. Therefore the older the reference the better. > > The current C standard is C17, with the last pre-certification draft > available freely and legally from the WG14 themselves at: > > <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2176.pdf> > > > C99, C11 and the latest draft of C2x are also available: > > <http://www.open-std.org/jtc1/sc22/wg14/www/projects> > > (You'll find the text in question in 6.5.8p8 and footnote 110). > Thanks. Yes, I found the quote in a draft standard before I found the K&R2 version. It's surprising that it was so little changed. -- James Harris
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-09-06 18:12 +0200 |
| Message-ID | <sh5ekt$85k$1@dont-email.me> |
| In reply to | #162642 |
On 06/09/2021 14:38, James Harris wrote: > On 06/09/2021 12:44, David Brown wrote: >> On 06/09/2021 13:18, James Harris wrote: >>> On 06/09/2021 09:27, James Harris wrote: >>>> On 05/09/2021 23:29, Stefan Ram wrote: >>> >>> ... >>> >>>>> Kernighan/Ritchie wrote: >>>>> >>>>> |The == (equal to) and the != (not equal to) operators are >>>>> |analogous to the relational operators except for their lower >>>>> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have >>>>> |the same truth-value.) >>>> >>>> Do you have a link to the source of that? >>> >>> No need to reply. I found it in A.7.10 of >>> >> >> Please do not post links to copyrighted books. I don't know if that >> link is legal or a copyright violation, but "some link I found with >> google" is certainly inappropriate. > > Not so. The book is published on the website of the Hasso Plattner > Institute in Germany. You can read about them at > > https://en.wikipedia.org/wiki/Hasso_Plattner_Institute > > I checked before posting the link that they were legitimate. They are a "real" institution, connected to a university, according to Wikipedia. > As such, > they have to take responsibility for what they publish and may well have > (or, will likely have) permission to do so, especially if they have had > the book on their website since 2019, as appears to be the case. > They could quite easily have got this wrong, or someone has published the book on their site without going through the proper checks and controls. It is perhaps unlikely that someone would knowingly and intentionally violate copyright with a link on the site, but mistakes happen. Assuming (and I'll assume that, until shown otherwise) they don't have rights to publish the book, then they should not have done so. However, that does not give /you/ the right to publish the link. It means you are both wrong, and both failed to make appropriate checks for a book that is so clearly and obviously copyrighted. >> >> It is also long out of date - TCPL is historically interesting, and a >> fine example of good technical writing, but not necessarily an accurate >> reference of current C - it formed the basis of the C standard, but has >> not been updated with the standard. > > I was asking for the source of the quote. Therefore the older the > reference the better. > A page number in the book would be a good reference. A link to a questionable (at best) copy of the book is not. > >> >> The current C standard is C17, with the last pre-certification draft >> available freely and legally from the WG14 themselves at: >> >> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2176.pdf> >> >> >> C99, C11 and the latest draft of C2x are also available: >> >> <http://www.open-std.org/jtc1/sc22/wg14/www/projects> >> >> (You'll find the text in question in 6.5.8p8 and footnote 110). >> > > Thanks. Yes, I found the quote in a draft standard before I found the > K&R2 version. It's surprising that it was so little changed. > Not really - changing as little as possible is the hallmark of C.
[toc] | [prev] | [next] | [standalone]
| From | tth <tth@none.invalid> |
|---|---|
| Date | 2021-09-06 18:20 +0200 |
| Message-ID | <sh5f43$dqi$1@news.gegeweb.eu> |
| In reply to | #162637 |
On 9/6/21 1:44 PM, David Brown wrote:
> The current C standard is C17, with the last pre-certification draft
> available freely and legally from the WG14 themselves at:
>
> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2176.pdf>
>
Enter the password to open this PDF file.
[Cancel] [OK]
--
+-------------------------------------------------------------------+
| sphinx of black quartz, judge my vow. |
+-------------------------------------------------------------------+
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-09-06 23:40 +0200 |
| Message-ID | <sh61sg$hh8$1@dont-email.me> |
| In reply to | #162650 |
On 06/09/2021 18:20, tth wrote: > On 9/6/21 1:44 PM, David Brown wrote: > >> The current C standard is C17, with the last pre-certification draft >> available freely and legally from the WG14 themselves at: >> >> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2176.pdf> >> > > Enter the password to open this PDF file. > [Cancel] [OK] > Odd. You can get it from the link here : <https://www.iso-9899.info/wiki/The_Standard> Certainly they did publish it freely, without any protection. (That is why I think it is fine to publish a link to it - you can also get the same link from the Wikipedia article.) The links from the WG14 project page <http://www.open-std.org/jtc1/sc22/wg14/www/projects> cover other draft standards without protection, but the C17 link currently has an early C2x draft rather than a late C17 draft.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-09-06 17:20 -0700 |
| Message-ID | <87tuixfd7g.fsf@nosuchdomain.example.com> |
| In reply to | #162635 |
James Harris <james.harris.1@gmail.com> writes:
> On 06/09/2021 09:27, James Harris wrote:
>> On 05/09/2021 23:29, Stefan Ram wrote:
> ...
>
>>> Kernighan/Ritchie wrote:
>>>
>>> |The == (equal to) and the != (not equal to) operators are
>>> |analogous to the relational operators except for their lower
>>> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have
>>> |the same truth-value.)
>> Do you have a link to the source of that?
>
> No need to reply. I found it in A.7.10 of
>
> https://[SNIP]/The_C_Programming_Language.pdf
That is almost certainly a pirated copy of K&R2, uploaded by an
individual at the institution who either did not know or did not care
that it's a copyright violation. (Let's not have an argument about
whether "pirated" is the appropriate word, please.)
My paper copy of that book has a copyright notice just before the table
of contents. It was omitted from the PDF, I presume deliberately.
If Bell Labs or Prentice Hall had ever given permission for K&R2 to be
freely published, I'm sure someone here would have heard about it.
Legitimate copies of K&R2 are available from various vendors, as are
used copies of K&R1 for those who are interested in the historical
context.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2021-09-06 13:44 +0100 |
| Message-ID | <87eea1kh4x.fsf@bsb.me.uk> |
| In reply to | #162630 |
James Harris <james.harris.1@gmail.com> writes: > On 05/09/2021 23:29, Stefan Ram wrote: >> James Harris <james.harris.1@gmail.com> writes: >>> Anyone know why the precedences were designed that way? >> The precedence of > < <= >= over == != was already >> present in B. > > Was that in just some versions of B? It looks as though relational and > equality comparisons are at the same level in > > https://www.thinkage.ca/gcos/expl/b/manu/manu.html#AppendixB > > Of course, that may not be right but I wonder if Thompson changed from > one set of precedence levels to the other, and why. Strange. The GCOS version was the only one I ever used, but I have no memory of the operator precedence. >> Kernighan/Ritchie wrote: >> |The == (equal to) and the != (not equal to) operators are >> |analogous to the relational operators except for their lower >> |precedence. (Thus a<b == c<d is 1 whenever a<b and c<d have >> |the same truth-value.) > > Do you have a link to the source of that? It's from the C book (K&R). Section 7.7 190, page 190 in the 1st edition. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-09-06 17:23 -0700 |
| Message-ID | <87pmtlfd38.fsf@nosuchdomain.example.com> |
| In reply to | #162630 |
James Harris <james.harris.1@gmail.com> writes:
> On 05/09/2021 23:29, Stefan Ram wrote:
>> James Harris <james.harris.1@gmail.com> writes:
>>> Anyone know why the precedences were designed that way?
>> The precedence of > < <= >= over == != was already
>> present in B.
>
> Was that in just some versions of B? It looks as though relational and
> equality comparisons are at the same level in
>
> https://www.thinkage.ca/gcos/expl/b/manu/manu.html#AppendixB
>
> Of course, that may not be right but I wonder if Thompson changed from
> one set of precedence levels to the other, and why.
https://www.bell-labs.com/usr/dmr/www/kbman.pdf
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2021-09-06 23:07 -0400 |
| Message-ID | <sh6l1u$lr9$1@dont-email.me> |
| In reply to | #162618 |
On 9/5/21 1:49 PM, James Harris wrote: > According to > > https://en.cppreference.com/w/c/language/operator_precedence > > and other references C applies relative comparisons (<, <=, >=, >) > before equality comparisons (==, !=) rather than giving them all the > same priority. > > Anyone know why the precedences were designed that way? > > Are there certain idioms in which that arrangement is useful? The "Rationale" is silent on this issue. Section 7.7 of K&R, 1st edition, after describing the lower precedence of == and !=, mentions that "Thus a<b == c<d is 1 whenever a<b and c<d have the same truth-value." I wouldn't say that "a < b == c < d" qualifies as idiomatic - but it is precisely the example I was planning to offer before I checked what K&R said about the matter. The key issue is not whether "a < b == c < d" is common, but only whether it's significantly more common that "a == b < c == d", which would be permitted if we reversed the precedences. The former is something I can imagine writing under some rare circumstances, whereas the latter is essentially equivalent to "a != b && c == d" (unless a or b might be NaNs), which in my opinion is the clearer way to write such an expression.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c
csiph-web