▲ 651 ▼ More code = more better (lemmy.zip) submitted 7 months ago by cm0002@lemmy.zip to c/programmer_humor@programming.dev 92 comments fedilink hide all child comments
[–] Hirom@beehaw.org 31 points 7 months ago (2 children) The compiler will optimize it anyway. /s permalink fedilink source hideshow 4 child comments replies: [–] Dumhuvud@programming.dev 17 points 7 months ago* (1 child) You jest, but you aren't wrong. At least if we are talking about C, C++ or Rust. https://godbolt.org/z/oPPfdfcf5 .NET compiler is weak when it comes to optimizing your code; I assume Go's is as bad. permalink fedilink source parent hideshow 2 child comments replies: [–] yggstyle@lemmy.world 4 points 7 months ago Technically yes... But I think he was more making the excuse for the gore "from the goresmith's perspective." And I'm not sure if the compiler in any language would change a random check function... The others are a possibility. permalink fedilink source parent [–] yetAnotherUser@discuss.tchncs.de 6 points 7 months ago (1 child) Not sure about the last one though. The other two are trivial to optimize away. permalink fedilink source parent hideshow 2 child comments replies: [–] Hirom@beehaw.org 3 points 7 months ago* (1 child) An infinite loop canot be ruled out in the last case, so a compiler couldn't optimize this away without potentially changing the program behavior. permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago (1 child) Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like. permalink fedilink source parent hideshow 2 child comments replies: [–] ronigami@lemmy.world 2 points 7 months ago (1 child) How could an infinite loop be considered UB? permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent
[–] Dumhuvud@programming.dev 17 points 7 months ago* (1 child) You jest, but you aren't wrong. At least if we are talking about C, C++ or Rust. https://godbolt.org/z/oPPfdfcf5 .NET compiler is weak when it comes to optimizing your code; I assume Go's is as bad. permalink fedilink source parent hideshow 2 child comments replies: [–] yggstyle@lemmy.world 4 points 7 months ago Technically yes... But I think he was more making the excuse for the gore "from the goresmith's perspective." And I'm not sure if the compiler in any language would change a random check function... The others are a possibility. permalink fedilink source parent
[–] yggstyle@lemmy.world 4 points 7 months ago Technically yes... But I think he was more making the excuse for the gore "from the goresmith's perspective." And I'm not sure if the compiler in any language would change a random check function... The others are a possibility. permalink fedilink source parent
[–] yetAnotherUser@discuss.tchncs.de 6 points 7 months ago (1 child) Not sure about the last one though. The other two are trivial to optimize away. permalink fedilink source parent hideshow 2 child comments replies: [–] Hirom@beehaw.org 3 points 7 months ago* (1 child) An infinite loop canot be ruled out in the last case, so a compiler couldn't optimize this away without potentially changing the program behavior. permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago (1 child) Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like. permalink fedilink source parent hideshow 2 child comments replies: [–] ronigami@lemmy.world 2 points 7 months ago (1 child) How could an infinite loop be considered UB? permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent
[–] Hirom@beehaw.org 3 points 7 months ago* (1 child) An infinite loop canot be ruled out in the last case, so a compiler couldn't optimize this away without potentially changing the program behavior. permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago (1 child) Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like. permalink fedilink source parent hideshow 2 child comments replies: [–] ronigami@lemmy.world 2 points 7 months ago (1 child) How could an infinite loop be considered UB? permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent
[–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago (1 child) Infinite loops are often weird though. They could be seen as undefined behavior and the compiler may do whatever it feels like. permalink fedilink source parent hideshow 2 child comments replies: [–] ronigami@lemmy.world 2 points 7 months ago (1 child) How could an infinite loop be considered UB? permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent
[–] ronigami@lemmy.world 2 points 7 months ago (1 child) How could an infinite loop be considered UB? permalink fedilink source parent hideshow 2 child comments replies: [–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent
[–] yetAnotherUser@discuss.tchncs.de 1 point 7 months ago Even though this isn't C, but if we take from the C11 draft §6.8.5 point 6 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf): An iteration statement whose controlling expression is not a constant expression, that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation to terminate "new Random().nextInt()" might perform I/O though so it could still be defined behavior. Or the compiler does not assume this assumption. But an aggressive compiler could realize the loop would not terminate if x does not become 10 so x must be 10 because the loop can be assumed to terminate. permalink fedilink source parent