Bug of the day
-
Wich compiler ?
while (*dest++ = *source++);
is completely correct, isn't it ?
Klaus-Werner Konrad wrote:
Wich compiler?
FTFY: Witch compiler Actually, in this case the C# produces three useless wormings: both for the "while(...);" (an empty statment), "x=y" (an assigment instead of a comparison) and the "*" (an "unsafe" code), does it?
Greetings - Jacek
-
Does that even compile? /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
No, it doesn't. But that's just the bug: it doesn't compile! [EDIT] I'm sorry, I didn't see the semicolon after the
if
statement. That's the bug! :doh:The quick red ProgramFOX jumps right over the
Lazy<Dog>
. My latest article: Understand how bitwise operators work (C# and VB.NET examples) My group: C# Programmers Group -
Klaus-Werner Konrad wrote:
Wich compiler?
FTFY: Witch compiler Actually, in this case the C# produces three useless wormings: both for the "while(...);" (an empty statment), "x=y" (an assigment instead of a comparison) and the "*" (an "unsafe" code), does it?
Greetings - Jacek
Thanks for the correction. My example was - as a reply to the mention of C, of course a C code snippet, and is the full working function body for strcpy(). Of course, it's unsafe - but lightning fast :-)
-
Klaus-Werner Konrad wrote:
Wich compiler?
FTFY: Witch compiler Actually, in this case the C# produces three useless wormings: both for the "while(...);" (an empty statment), "x=y" (an assigment instead of a comparison) and the "*" (an "unsafe" code), does it?
Greetings - Jacek
They're not useless warnings, they're warning you that you did something unintended. Actually this wouldn't compile at all in C#, even with unsafe mode turned on, because the result type isn't boolean. It's a classic and well known piece of C code, and I think you only got a warning for the empty loop body (and if you did if(a = 3) by accident you were just screwed, hence writing if(3 == a) instead which is an error if you screw it up).
-
Thanks for the correction. My example was - as a reply to the mention of C, of course a C code snippet, and is the full working function body for strcpy(). Of course, it's unsafe - but lightning fast :-)
-
They're not useless warnings, they're warning you that you did something unintended. Actually this wouldn't compile at all in C#, even with unsafe mode turned on, because the result type isn't boolean. It's a classic and well known piece of C code, and I think you only got a warning for the empty loop body (and if you did if(a = 3) by accident you were just screwed, hence writing if(3 == a) instead which is an error if you screw it up).
-
if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...
Ooh, nasty! Couldn't see it at first.
Check out my latest article: Celerity: How it was all done. A complete how-to on our sensor-driven head-tracking virtual reality tunnel game in C#.
-
if(SomeThing == SomeOtherThing); { DoSomeThing; } This one has been sitting in the codebase for a couple of years... :(( At least it did SomeThing...
Delphi4ever wrote:
if(SomeThing == SomeOtherThing);
I remember years ago spending a few hours debugging why (in C++):
for (int i=0; i<10; i++);
DoSomething();where DoSomething executed only once. I only had to learn that lesson once! :rolleyes: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My Blog -
I've worked with people who did this:
if condition
DoSomething();
else
{
DoOtherThing1();
DoOtherThing2();
}or
if condition
{
DoSomething1();
DoSomething2();
}
else
DoOtherThing();Both of which give me the creeping heebie-jeebies.
Software Zen:
delete this;
-
It's valid syntax, and if you're confident that you'll never ever forget to add or remove braces appropriately, go for it.
Software Zen:
delete this;