- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Ahh you youngsters probably don't remember the for-while loop. The good olde days.
Admin
This code ain't for no boundary overrun prevention, nossir! It's actually a very clever, ingenious, way to add a NOP on the program, so that the snipped become 32bit-aligned!
Admin
I always use these when I only want my code to run for a while.
Admin
I see the article contains 138 characters in total. Neat. This comment has even fewer.
Admin
It took me a few moments to understand the "Gordon's c/w came up w/ this".
Admin
It's too long this way! Just take away some vowels, nobody will notice. :-)
Admin
I once wrote this for loop:
Admin
Re:José Rodrigues
a good compiler would optimize that instruction out
Admin
Admin
"a good compiler would optimize that instruction out"
A bad programmer would forget to use the good compiler's optimization flags.
Admin
Good thing you abbreviated co-worker and with, the story was so long it started to get boring.
Admin
You remembered that only fools assume bytes are 8 bits?
Admin
while (1); or any other number probably didn't work, but 0 appeared to correct the problem.
Admin
noob question: the byte is signed, right?
Admin
tldr
Admin
Admin
Heh, I had a boundary overflow problem once or twice with Delphi code.
I wrote this apparently simple snippet of code:
for i:=start to end do // code
which however appeared to freeze everything, as if start > end when the loop is started it will apparently run forever...or for very long, depending on what i is (an Integer however will take pretty long...). Why? Because Delphi implies only a precise equality as the loop ending condition. No "greater or equal" here. The solution was to either replace the for loop with a "while (condition) do" construct, or explicitly checking for the start>end condition before the if.
Admin
What are you doing? Rdng TDWTF n lol @ code
Admin
The byte is NOT signed, but it will overflow (the b++ overflows the byte), so it should go to 0. Infinite loop.
Nice. Jim.
Admin
doh! I didn't read the = so imagined the overflow already at 127++
Admin
Admin
tl;dr
Admin
Admin
I did that once. Took me far too long to figure out why it wouldn't end.
Admin
Reminds me of this fortune: [Temperature 13 C][16:28:13 01-April-09][/home/adam] [adam@owl]$ fortune -m "f u cn" %% (fortunes) f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.
Admin
Don't be silly. Eight bits is a dollar.
Admin
I once saw this while loop:
G++ with -O3 turned it into an infinite loop. It's not even a bug.
Admin
My favourite is always this one - I keep finding that my finigers typo it!
Admin
At first I thought I was looking at a for...while loop. But it turns out the ; substitutes for the body of the while loop, so it's exactly the same as:
Admin
Um, no. While the terminating condition of a for loop is strict equality in Delphi, the runtime also checks that Start <= End. If Start > End, then it will skip the loop altogether. Also, End is only evaluated once for for loops in Delphi (e.g. If End is really a function call, the function is only called once at the first check.). For a while loop, the condition is evaluated for every iteration.
Ergo, checking for Start > End before entering a for loop doesn't do anything unless End is a function call with a side effect, and while loops have subtly different semantics that can make a difference.
Admin
the e in olde: extra character!
Admin
I call Shenanigans. The
was very obviously and poorly Photoshopped in.Admin
It's too long to re-tweet.
Admin
Delphi 7, d'oh. And it just froze when ran: debugging the loop revealed that the index variable was merrily stepping its way up to MAXINT and then from -MAXINT...go figure.
Start and End were variables in my case, and I used the default project options. It sure made me go "WTF" when I realized it, and chose the easiest workaround, since I really needed the index variable inside the loop, and felt that increasing them myself just made the whole code look uglier.
Admin
Everybody's routing through Twitter now.
Admin
One of the nastiest practical jokes I ever read about was how to totally confuse C programmers. To do this, you bury this DEFINE in some ob
Admin
scure header file:
Admin
I once did this...
Then you can do...
A coworker saw it and added the comment:
Admin
Actually, if you count all new lines its 142 characters, and if this was encoded in windows format, its more like 149 characters. There's the real WTF.
Admin
Admin
Admin
No. In Java it doesn't. Boolean values in Java are really true or false, not 0 or !0.
Admin
If you put a newline before the while(0); it will be immediately obvious what this code does. But when you first look at it, it does make you go "huh".
It is a fair criticism of C/C++ that non-standard indentation can mislead you as to what the code is doing. This code is a good example of that.
Admin
Ouch... yet another python fanatic
Admin
This was also posted on April 1st but there is no such thing as a for...while construct and they are two separate loops in the code.
Admin
This is C++ mate :). Strictly, you can only declare variables in the beginning of a code block / function and not in the head of a for loop (for (int i = 0 ...). Thats wtf :P
Admin
EDIT: ..Strictly speaking, you can only declare variables ....
Admin
Admin
I'm sure the performance boost was amazing too
Admin
C99 allows this.