Re: while(T[l]<p & l<=r)

Liste des GroupesRevenir à cl c  
Sujet : Re: while(T[l]<p & l<=r)
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 28. Mar 2024, 21:36:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uu4gqv$3p07m$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 28/03/2024 17:12, fir wrote:
bart wrote:

Of all the ugly things in C, you have to pick on &&? In any case, that's
the correct operator to use here, since && is quite different from &:
>
     if (length(s) & length(t))
>
     if (length(s) && length(t))
>
Suppose s is "AB" and t is "ABCD". Then the version using & will do 2 &
4 which is zero: so FALSE.
>
The version using && will be 2 && 4 which is 1, so TRUE, a completely
different result.
>
Also, if s was "", then the version using && short-circuits, so it won't
bother evaluating length(t); it is more efficient.
>
Also, as you've discovered, & has a different and less suitable
precedence compared to &&.
>
>
If you really hate '&&' then try including <iso646.h>. Now you can do this:
>
     if (length(s) and length(t))
>
But let me guess; that's too long-winded? 'A and B' instead of 'A&&B'
because 'and' needs that white space.
 should be A&B and everything looks liek it should
You haven't read my post properly have you?
& and && do quite different things; I listed 3 major ways in which they differ.
Here's another:
     float x=k, y=k;
     if (x && y)           // this will work as expected
     if (x & y)            // this won't compile

thsoe with length are weird programming i dont use it,
using & is not totally proper taking c history but && for me is also not fully proper taking c 'style' and & i find just better
OK. You can make & work a bit like && if you turn:
     A && B
where A and B are arbitrary expressions, into:
    !!(A) & !!(B)
But you still won't get short-circuit behaviour.

Date Sujet#  Auteur
27 Mar 24 * while(T[l]<p & l<=r)18fir
28 Mar 24 +* Re: while(T[l]<p & l<=r)15Janis Papanagnou
28 Mar 24 i+* Re: while(T[l]<p & l<=r)7fir
28 Mar 24 ii`* Re: while(T[l]<p & l<=r)6Janis Papanagnou
28 Mar 24 ii `* Re: while(T[l]<p & l<=r)5fir
28 Mar 24 ii  `* Re: while(T[l]<p & l<=r)4bart
28 Mar 24 ii   `* Re: while(T[l]<p & l<=r)3fir
28 Mar 24 ii    `* Re: while(T[l]<p & l<=r)2bart
29 Mar 24 ii     `- Re: while(T[l]<p & l<=r)1fir
28 Mar 24 i+* Re: while(T[l]<p & l<=r)2David Brown
28 Mar 24 ii`- Re: while(T[l]<p & l<=r)1Kaz Kylheku
30 Mar 24 i+* Re: while(T[l]<p & l<=r)3Tim Rentsch
30 Mar 24 ii`* Re: while(T[l]<p & l<=r)2fir
9 Apr 24 ii `- Re: while(T[l]<p & l<=r)1Tim Rentsch
31 Mar 24 i+- Re: while(T[l]<p & l<=r)1fir
14 Apr 24 i`- Re: while(T[l]<p & l<=r)1Phil Carmody
3 Apr 24 `* Re: while(T[l]<p & l<=r)2Peter 'Shaggy' Haywood
3 Apr 24  `- Re: while(T[l]<p & l<=r)1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal