February 29, 2004
I didn't no that there was a difference between || and | in terms of the
evaluation order.
I just remembered that for most of the time there is no defined order. :)

-- 
Jan-Eric Duden
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
news:c1sq61$1ukb$1@digitaldaemon.com...
> Jan-Eric Duden wrote:
>
> >>if( !read(&b,4) ||
> >>    !read(&c,10) ||
> >>    !read(&d,13) ||
> >>    !read(&e,3) ||
> >>    !read(&f,14) )
> >>{
> >>    return false;
> >>}
> >>
> >>
> >>>It is not clear in what order the reads are being executed.
> >>>
> >>>
> >>>
> >>>
> >>>
> >>It is perfectly clear.
> >>
> >>
> >
> >Is that order defined in the language specification?
> >
> >
> >
> Yep (part of the C specification which is carried on to D), the || is a short circuit, so it must go in the order given.  If !read(&b,4), it must stop there.  However, if you used | then it would need to test everything in the sequence regardless.  If there wasn't this certainly, the short circuit would be useless.
>
> Note that in some cases the compiler can optimise short circuits, but only when it can be absolutely sure that there will be no side effect, so that is no problem.
>
> -- 
> -Anderson: http://badmama.com.au/~anderson/


February 29, 2004
Jan-Eric Duden wrote:

>I didn't no that there was a difference between || and | in terms of the
>evaluation order.
>
>
>  
>
Also what is important is that | is used for binary operations where as || is not.  The same applies to & and && as in the following example:

   int a = 2;
   int b = 4;
     if ( a & b ) printf("a & b\n"); //if a AND b != 0
   if ( a && b ) printf("a && b\n"); //if a != 0 and then if b != 0

Outputs:
a && b

>I just remembered that for most of the time there is no defined order. :)

Either your memory is faulty (I'd take it back for a replacement ;) ) or your thinking of a different language.


-- 
-Anderson: http://badmama.com.au/~anderson/
February 29, 2004
Jan-Eric Duden wrote:
> Of course, i could write my own 'non-standard' stream library...
> which fixes all the problems but then it is not the standard stream library
> and won't help other people to prevent bugs.

I guess it's a matter of background.  I'm used to C++ where there's no hand-holding at all and I like it that way.  Others from a Java background might have a different opinion.  I personally hate the Java standard library and would code my own rather than use a re-packaged duplicate in D :)


Sean
February 29, 2004

-- 
Jan-Eric Duden
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
news:c1t883$2mpg$1@digitaldaemon.com...
> Jan-Eric Duden wrote:
>
> >I didn't no that there was a difference between || and | in terms of the evaluation order.
> >
> >
> >
> >
> Also what is important is that | is used for binary operations where as || is not.  The same applies to & and && as in the following example:
>
>     int a = 2;
>     int b = 4;
>
>     if ( a & b ) printf("a & b\n"); //if a AND b != 0
>     if ( a && b ) printf("a && b\n"); //if a != 0 and then if b != 0
>
> Outputs:
> a && b
yep, that's the obvious difference between || and |. | is bitwise and || is logical.

>
> >I just remembered that for most of the time there is no defined order. :)
>
> Either your memory is faulty (I'd take it back for a replacement ;) ) or
your thinking of a different language.
There is no defined order for all the other operators.  , || and && are the
exception. so my assumption was just the safe one. :)



February 29, 2004
I guess you can't make everyone happy. :)
You can just hope that you make the majority happy and I guess that's
already difficult enough. :)

-- 
Jan-Eric Duden
"Sean Kelly" <sean@ffwd.cx> wrote in message
news:c1t9s4$2pb8$1@digitaldaemon.com...
> Jan-Eric Duden wrote:
> > Of course, i could write my own 'non-standard' stream library... which fixes all the problems but then it is not the standard stream
library
> > and won't help other people to prevent bugs.
>
> I guess it's a matter of background.  I'm used to C++ where there's no hand-holding at all and I like it that way.  Others from a Java background might have a different opinion.  I personally hate the Java standard library and would code my own rather than use a re-packaged duplicate in D :)
>
>
> Sean


February 29, 2004
These are short-circuit || ops.  If the left side is true, the right side is not executed - entire expression must be evaluated left to right, and the first true stops evaluation and if is satisfied so false is returned.

In article <c1sd0l$18ut$1@digitaldaemon.com>, Jan-Eric Duden says...
>
>>if( !read(&b,4) ||
>>     !read(&c,10) ||
>>     !read(&d,13) ||
>>     !read(&e,3) ||
>>     !read(&f,14) )
>>{
>>     return false;
>>}
>> >It is not clear in what order the reads are being executed.
>> >
>> >
>> >
>> It is perfectly clear.
>
>Is that order defined in the language specification?
>
>-- 
>Jan-Eric Duden
>"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
>news:c1qhut$umj$4@digitaldaemon.com...
>> Jan-Eric Duden wrote:
>>
>> >It is not clear in what order the reads are being executed.
>> >
>> >
>> >
>> It is perfectly clear.
>>
>> >And may be you want to do some stuff in between.
>> >
>> >
>> That is a good point.
>>
>> -- 
>> -Anderson: http://badmama.com.au/~anderson/
>
>


March 01, 2004
Sorry - my messages were out of order - this was already answered.

In article <c1tu8e$qq8$1@digitaldaemon.com>, larry cowan says...
>
>These are short-circuit || ops.  If the left side is true, the right side is not executed - entire expression must be evaluated left to right, and the first true stops evaluation and if is satisfied so false is returned.
>
>In article <c1sd0l$18ut$1@digitaldaemon.com>, Jan-Eric Duden says...
>>
>>>if( !read(&b,4) ||
>>>     !read(&c,10) ||
>>>     !read(&d,13) ||
>>>     !read(&e,3) ||
>>>     !read(&f,14) )
>>>{
>>>     return false;
>>>}
>>> >It is not clear in what order the reads are being executed.
>>> >
>>> >
>>> >
>>> It is perfectly clear.
>>
>>Is that order defined in the language specification?
>>
>>-- 
>>Jan-Eric Duden
>>"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
>>news:c1qhut$umj$4@digitaldaemon.com...
>>> Jan-Eric Duden wrote:
>>>
>>> >It is not clear in what order the reads are being executed.
>>> >
>>> >
>>> >
>>> It is perfectly clear.
>>>
>>> >And may be you want to do some stuff in between.
>>> >
>>> >
>>> That is a good point.
>>>
>>> -- 
>>> -Anderson: http://badmama.com.au/~anderson/
>>
>>
>
>


1 2 3
Next ›   Last »