Re:A Defer Mechanism for C
by josephcsible on Monday December 14, 2020 @11:56AM
(#25419794)
With a while loop, to know what happens at the bottom of the block, you only need to check the top of the block. With defer, to know what happens at the bottom of the block, you need to check the entire contents of the block.
[ Parent
| on HN ]
What? Any statement inside a while loop could mutate the loop variable and then all bets are off.
You have to check every line of a while loop to know what’s going on. Heck, another thread could hold a pointer aliasing the loop variable and then mutate it, causing the loop to terminate for no obvious reason.
Re:A Defer Mechanism for C
by josephcsible on Monday December 14, 2020 @05:28PM
(#25424243)
My point is that you know at the end of the while loop, it's going to test the loop variable you wrote at the beginning, no matter what's in the loop body. The fact that other things could change the variable isn't relevant. With defer, you don't know what will happen at the end of a block without looking through the whole thing.
Why does it matter so much what code runs at the end of a block?
Re:A Defer Mechanism for C
by IAmADHDToo on Monday December 14, 2020 @03:02PM
(#25422460)
> With a while loop, to know what happens at the bottom of the block, you only need to check the top of the block.
Anyway, what could possibly happen at the end of a while loop, besides going back to the begining for the test?
Besides, if you have a bug in your code, you will have to look at the whole block anyway.