On Aug 3, 2011, at 8:27 PM, Graham Cox wrote:

> 
> On 04/08/2011, at 11:19 AM, Greg Parker wrote:
> 
>>> This is a classic question for coding job interviews.
>> 
>> Incorrect.
> 
> 
> Ah well, I guess I didn't get the job :)
> 
> In my defence, I saw this in a job interview but it was prior to 1999. Maybe 
> C99 tightened up on something that was previously vague.
> 
> --G.
> 

My copy of K&R  © 1978 says:

"More interesting are the logical connectives && and ||.  Expressions connected 
by && or || are evaluated left to right, and evaluation stops as soon as the 
truth or falsehood of the result is known.  These properties are critical to 
writing programs that work."

(p 38)

and later in Appendix A: C Reference Manual:

"Unlike &, && guarantees left-to-right evaluations; moreover the second operand 
is not evaluated if the first operand is 0"

(p190, section 7.11 Logical AND operator)

"Unlike |, || guarantees left-to-right evaluations; moreover the second operand 
is not evaluated if the first operand is non-zero"

(p191, section 7.12 Logical OR operator)


Nothing vague there.  More likely the somebody that interviewed you didn't have 
it correct in the first place, scarring you for life...


Glenn Andreas                      gandr...@gandreas.com 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to