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

Liste des GroupesRevenir à l c 
Sujet : Re: while(T[l]<p & l<=r)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 28. Mar 2024, 17:26:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uu4269$3lf5i$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 28.03.2024 13:18, fir wrote:
Janis Papanagnou wrote:
On 27.03.2024 12:35, fir wrote:
tell me, is while(T[l]<p & l<=r) the same as while((T[l]<p)&&(l<=r))
>
[...] If
you don't want to operate on bits but want to express a boolean
conjunction you should use '&&', though.
 
[...]
 
hovever i wopuld disagre to use "&&" instead "&" then
&& look much worse

(Well, I think that '+' looks much worse than '*', but in
math expressions I use the _appropriate_ operator anyway.)

Mind that '&' is *not* a syntactical variant of '&&'...

and probably & has no real disadvantages

it is different to '&&', it has another semantic! As said,
it's just by context-coincidence that it's equivalent _here_.

(i mean no
bigger that the intention that && should be use for boolean - which
probably comes from later c not oryginal young c

Original K&R C had '&' for bit-operations and '&&' for boolean
operations.

While, say, 'x<y & u<v' works effectively as 'x<y && u<v' (as
said, because of the evaluations to 0 and 1, general boolean
predicates, like 'p() & q()' is not the same as 'p() && q()',
even if you can use 'p()' and 'q()' in 'if'-conditions as per
the C semantics of booleans (or integers used as booleans).

You often see code like,say, 'x=length(s); y=length(t);' and
compare non-emptiness of the strings with 'if (x)' or with
'if (y)'. If you combine that condition by 'if (x & y)' you
will get wrong results, but 'if (x && y)' would be correct.

'&' is for bit-operations in scalars, '&&' is for booleans
(for logical operations, bool x bool -> bool).

 
so i probably plan to stick to &

But why stick to a bit-value operator where you want a
boolean logic operator? - You just confuse readers of your
code and unnecessarily introduce error-prone code.

(But you can of course do as you like.)

Janis


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