|
A classic C/C++ error; you haven't been coding long enough if you haven't run into this one before.
Steve
|
|
|
|
|
I've been coding for about 5 years of my life. Maybe its more of the experience though. Since I haven't really encountered this until last time.
|
|
|
|
|
Ooh, that's a good one. I've had it before as well, and even now only after reading the first comment did I get it. I was going to say, it's not really a horror because we don't know what MIN_VAL and MAX_VAL are.
|
|
|
|
|
Here, have one of these:
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
if it makes you feel any better, it took me about 5 mins of looking at it over and over again before i noticed what you were talking about
|
|
|
|
|
|
me too, then i saw it, the bug is on *beeeeeeeeep!* right there
|
|
|
|
|
*beeeep*
what's wrong...can't say "semicolon" ???
caridad
|
|
|
|
|
nice one! actually it did!
|
|
|
|
|
I didn't get it until Marc's comment about the body only running once.
This blanket smells like ham
|
|
|
|
|
I had to look for help
xacc.ide
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Switch to a language that does not have loops (Haskell, for instance) and you won't have these problems any more
|
|
|
|
|
Oh my god....and I was looking ....and looking....and looking....
The conditional statement was fine....and I couldn't find it at all....keep looking and reading all the comments here. Couldn't find it.
I was about to give up and ask when BLAM!!!!! I saw it...there...
That never happened to me. Luckily! I've done similar though and lost a good 3~4 hours of time trying to figure it out.
I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?
Dewm Solo - Managed C++ Developer
|
|
|
|
|
Dewm Solo wrote: Shouldn't the compiler complain about this?
No, it's perfectly valid to stuff all of the loops processing into the ( ; ; ) of a for statement and create a loop with no explicitly defined code block. This has it's uses, but I always just enjoyed using it to obfuscate my code
|
|
|
|
|
Dewm Solo wrote:
I am actually surprised that this compiles though...and runs. Shouldn't the compiler complain about this?
Yeah. While it should of course compile, I'd want this warning: http://msdn2.microsoft.com/en-us/library/9x19t380(vs.80).aspx[^]
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Indeed! Right on the button.
Dewm Solo - Managed C++ Developer
|
|
|
|
|
Dammit, I had to stick this in the IDE and debug it to work out what the hell was wrong with this. I think I've been doing a little too much ASP maintenance today
|
|
|
|
|
I was starting to get mad at this code, thinking it is one of those "inside" jokes where everybody laughs until you start laughing, then they laugh harder cause there is no joke. Nobody said what the problem was. Then after reading all the comments, I went back and reviewed it again. I found the issue! Funny how it never shows up till the end.
Hogan
|
|
|
|
|
yes, just like the code when you encounter it. wasn't funny until you end up looking at it for 30 or so minutes and seeing that the semicolon was the problem.
|
|
|
|
|
When happened to me, I thought for a (long) while about a compiler bug, before finding the ****** semicolon.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
took me about five seconds to see the error.
maybe I've stumbled into most sh*t already.
Larswad
|
|
|
|
|
A simple example of how not to copy a string...
sprintf(packet.data.header.filter, "%s", "wild");
it works, I suppose.
Rob Grainger
|
|
|
|
|
The ones I love are these (assuming 8-bit characters) :
strncpy( szDestination, szSource, sizeof(szSource) );
or
strncpy( szDestination, szSource, strlen(szSource) );
or
strncpy( szDestination, szSource, strlen(szDestination) );
|
|
|
|
|
For us noobs, what is wrong with the last one? At least it uses the destination length.
|
|
|
|
|
I am noob too, but I dare to guess that it loses terminating zero.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|