|
|
Actually, the result is the same. The side-effects aren't. At least in C#. In C, with it's enforced type-unsafety, the result can be extremey weird and the compiler won't do jack to even warn you.
|
|
|
|
|
No. Example
2 & 4 is 0
2 && is 1 (true)
In that case I needed the first form as I was checking for a flag in a flag register, but mistakenly used the second form due to, well, being the most common (althought not so much in my field, which requires the management of a lot of driverless hardware).
CALL APOGEE, SAY AARDWOLF
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
"Go ahead, make my day"
|
|
|
|
|
That depends on the language. In a strongly typed language, 1 and true aren't the same because one is a number and true is a boolean. So 2&4 is 0 and 2&&4 is 0 as well, however the difference is in side effects.
SomeFunc & SomeOtherFunc will execute both functions with their side-effets, SomeFunc && SomeOtherFunc will stop executing if SomeFunc returns false.
PS: I am talking about C# here which is, unlike C and C++, a strongly-typed language.
|
|
|
|
|
Don't feel bad. I once had a bug based on this very thing that took weeks to find.
Software Zen: delete this;
|
|
|
|
|
How this difference can hurt.
m is length of string = 3;
*b is first character in string say "xyz"
while( *b & m-- ) { b++; } is not the same as while( *b && m-- ) {b++;}
because
while( *b & m-- ) { b++; } fails when *b is null tested AND m is decremented at the same time ergo m is off by 1
while( *b && m-- ) { b++; } fails when *b is null tested. m is not decremented
because of the short circuit test of *b stops the evaluation
ergo m has the correct character count
so yes & and && are not the same so be careful of the logic when using C
|
|
|
|
|
Happy Australia Day?
Hope you all have a good one?
Don't drink too much?
|
|
|
|
|
Are you sure?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Yes he is?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I thought Shaw was a dead Irish playwright.
veni bibi saltavi
|
|
|
|
|
RyanDev wrote: There are two kinds of people in the world: those who can extrapolate from incomplete data. That's actually deep.
Jeremy Falcon
|
|
|
|
|
|
Pom Pey wrote: Happy Australia Day?
Hope you all have a good one?
Don't drink too much?
I'm not from Australia, but I've heard that on Australia Day, it is not possible to drink too much...
I'm retired. There's a nap for that...
- Harvey
|
|
|
|
|
H.Brydon wrote: I'm not from Australia, but I've heard that on Australia Day, it is not possible to drink too much...
That is true and I'm putting the theory to test as we type.
Michael Martin
Australia
"I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible."
- Mr.Prakash One Fine Saturday. 24/04/2004
|
|
|
|
|
My favourite Italian chef has quit – he said he cannoli do so much.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
He was good once but then started living off the glories of the pasta.
CALL APOGEE, SAY AARDWOLF
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
"Go ahead, make my day"
|
|
|
|
|
I think that's a load of bologna!
veni bibi saltavi
|
|
|
|
|
|
Tell him to leave the gun.
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
When he got home his wife asked "How'd your Dago?"
In this present crisis, government is not the solution to our problem; government is the problem. ~ Ronald Reagan
|
|
|
|
|
You should have just replied pasta la vista.
|
|
|
|
|
I heard he got fired, he was hitting the sauce too much.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
A real pizza work, that post.
Normally, I rotoni what I needed to post . . . orzo I though . . .
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Olive us know that a TotD is integrale humor, or so Ceci.
|
|
|
|
|
I bet he told his boss to "Stick it innuendo!"
|
|
|
|