| « Prev | Page 1 | Page 2 | Next » |
|
Ahh you youngsters probably don't remember the for-while loop. The good olde days.
|
|
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!
|
|
I always use these when I only want my code to run for a while.
|
|
I see the article contains 138 characters in total.
Neat. This comment has even fewer. |
|
It took me a few moments to understand the "Gordon's c/w came up w/ this".
|
|
It's too long this way! Just take away some vowels, nobody will notice. :-)
|
|
I once wrote this for loop:
|
Re: A Common C Dilemma
2009-04-01 09:11
•
by
SomeC++Dude
(unregistered)
|
|
Re:José Rodrigues
a good compiler would optimize that instruction out |
Re: A Common C Dilemma
2009-04-01 09:13
•
by
Zapp Brannigan
(unregistered)
|
I haven't used C for a while so I had to think for a second. That's nice. |
|
"a good compiler would optimize that instruction out"
A bad programmer would forget to use the good compiler's optimization flags. |
|
Good thing you abbreviated co-worker and with, the story was so long it started to get boring.
|
Re: A Common C Dilemma
2009-04-01 09:37
•
by
Flanged Magnet
(unregistered)
|
|
You remembered that only fools assume bytes are 8 bits?
|
|
while (1); or any other number probably didn't work, but 0 appeared to correct the problem.
|
Re: A Common C Dilemma
2009-04-01 09:46
•
by
ledhund
(unregistered)
|
|
noob question: the byte is signed, right?
|
Re: A Common C Dilemma
2009-04-01 09:55
•
by
ross
(unregistered)
|
It's probably not signed. But it is always going to be less than or equal to 255. Since the range of values is 0~255 |
|
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. |
|
What are you doing?
Rdng TDWTF n lol @ code |
Thinking here. I never did do C, but I did teach C++ once on TV. The byte is NOT signed, but it will overflow (the b++ overflows the byte), so it should go to 0. Infinite loop. Nice. Jim. |
Re: A Common C Dilemma
2009-04-01 10:02
•
by
ledhund
(unregistered)
|
doh! I didn't read the = so imagined the overflow already at 127++ |
Re: A Common C Dilemma
2009-04-01 10:15
•
by
Zapp Brannigan
(unregistered)
|
Also old farts like me. But then it's not an exclusive or. |
I'm scared that I read and understood it without even realizing they were abbreviated. o_o |
Re: A Common C Dilemma
2009-04-01 11:18
•
by
Ryan
(unregistered)
|
|
I did that once. Took me far too long to figure out why it wouldn't end.
|
Re: A Common C Dilemma
2009-04-01 11:31
•
by
lolcoder
(unregistered)
|
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. |
Don't be silly. Eight bits is a dollar. |
I once saw this while loop:
G++ with -O3 turned it into an infinite loop. It's not even a bug. |
|
My favourite is always this one - I keep finding that my finigers typo it!
for(int i=0; i<end; i++); |
|
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:
for (int i=0;i<max; i++) {
Plus this way it works in Java as well as C. |
Re: A Common C Dilemma
2009-04-01 12:47
•
by
Ardax
(unregistered)
|
|
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. |
Re: A Common C Dilemma
2009-04-01 13:10
•
by
WillowAnne
(unregistered)
|
|
the e in olde: extra character!
|
|
I call Shenanigans. The
while(0)was very obviously and poorly Photoshopped in. |
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. |
Re: A Common C Dilemma
2009-04-01 15:31
•
by
a guy
(unregistered)
|
|
Everybody's routing through Twitter now.
|
|
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
|
|
scure header file:
#DEFINE do if |
|
I once did this...
#define EverAndEver ;; Then you can do... for (EverAndEver) {
A coworker saw it and added the comment: for (EverAndEver) { // Hallelujah, Hallelujah!
|
|
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.
|
Re: A Common C Dilemma
2009-04-02 05:17
•
by
Random guy
(unregistered)
|
Hey, it works just as coded. :-) |
Only on slow machines. |
Re: A Common C vs. Java Dilemma
2009-04-02 06:04
•
by
SCJP
(unregistered)
|
No. In Java it doesn't. Boolean values in Java are really true or false, not 0 or !0. |
|
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. |
|
Ouch... yet another python fanatic
|
|
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.
|
|
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
|
Re: A Common C Dilemma
2009-04-03 09:12
•
by
pbi
(unregistered)
|
EDIT: ..Strictly speaking, you can only declare variables .... |
And your Captcha was..? |
|
I'm sure the performance boost was amazing too
|
|
Most importantly, lonely from obtains warm with the runescape glod person contact and to person's new understanding. I knew that these words are specious. Perhaps some people will ask: The runescape money lonely person, is not because the lonely essence is very only then difficult with the human to associate? Actually just right opposite, lonely person especially qualify and with others establishment relations. The runescape accounts reason is very simple: Because lonely. In the impression had a mind the scientist once to make such elaboration probably:"lonely not necessarily conflicts with the contact, because does not have one to be able to need the companion compared to the lonely person."
|
| « Prev | Page 1 | Page 2 | Next » |