:: Re: [DNG] [OT] [Re: Studying C as t…
Inizio della pagina
Delete this message
Reply to this message
Autore: Simon Walter
Data:  
To: dng
Oggetto: Re: [DNG] [OT] [Re: Studying C as told. (For help)
On 06/21/2016 06:09 PM, KatolaZ wrote:
> On Tue, Jun 21, 2016 at 05:47:59PM +0900, Simon Walter wrote:
>
> [cut]
>
>>> Be careful, because conditional expressions in C are subject to
>>> "short-circuiting", meaning that only the minimum number of
>>> expressions sufficient to determine the value of a chain of && and ||
>>> will be evaluated. In particular, a chain of || expressions will be
>>> evaluated until there is one that evaluates to TRUE (!=0), while a
>>> chain of && is evaluated until there is one of them which evaluates to
>>> false (==0).
>>>
>>
>> Isn't that how AND and OR work in most programming languages? Mind you, I am
>> not familiar with that many.
>
> I didn't say that short-circuiting is a peculiarity of C :)


Aha! You certainly didn't. I was surprised that "non-short-circuiting"
logical operators even existed.

> I simply
> said that short-circuiting is how C evaluates conditional
> expressions. There are many cases (such as that of FORTRAN) in which
> short-circuiting can be enabled or disabled at compile time, many
> other cases (e.g. most of the dialects of BASIC and some other
> esoteric languages) in which short-circuting does not exist, and many
> more cases in which the language supports both eager and short-circuit
> boolean operators (e.g., Java, Python, Perl, Ruby, etc.)
>
> Boolean expressions in C are always subject to short-circuting.
>


Interesting. And here I was taking "short-circuiting" for granted. Well,
you learn something new everyday. I will be sure to keep that in mind.

Can you to point me to those other operators that do not "short-circuit"
in Java, Python, Perl, and Ruby? Are the operators different, or do you
have to change the behaviour with a switch?

I am thinking we might use single ampersand or pipe (bitwise). Can we
use bitwise operators as what would be a non-short-circuiting logical
operator in C (or other languages)?

Very interesting!

Simon