MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/22lj4a/theo_de_raadt_openssl_has_exploit_mitigation/cgoo8rg/
r/programming • u/[deleted]
[deleted] — view deleted post
661 comments sorted by
View all comments
Show parent comment
4
You can toggle a switch and act on it at the same time. I actually like this one (*hides*).
if ((toggle = !toggle)) { ... } else { ... }
1 u/wescotte Apr 10 '14 I kinda like that too actually but I'd probably find it more useful inwhile ( (toggle = !toggle) ) { ... }since your else clause can never actually execute. 3 u/[deleted] Apr 10 '14 The else clause is called when toggle is originally true. :)To make it more clear here is a real world example.main() { bool isOn = false; while(1) { if ((isOn = !isOn)) { // Turn the light on. } else { // Turn the light off. } sleep(1); } }This is the hello world program for embedded things with LEDs. 2 u/knome Apr 10 '14 since your else clause can never actually execute.uhm...#include <stdio.h> int main( int argc, char ** argv ){ unsigned int toggle = 1 ; if( (toggle = !toggle) ){ printf( "does not print\n" ); } else { printf( "does\n" ); } return 0; }...$ gcc toggle.c $ ./a.out does 1 u/wescotte Apr 10 '14 Oh duh.. reduces to if (toggle) which evaluates to false. For some reason I was thinking leftHandSide = rightHandSide always reduces to true.
1
I kinda like that too actually but I'd probably find it more useful in
while ( (toggle = !toggle) ) { ... }
since your else clause can never actually execute.
3 u/[deleted] Apr 10 '14 The else clause is called when toggle is originally true. :)To make it more clear here is a real world example.main() { bool isOn = false; while(1) { if ((isOn = !isOn)) { // Turn the light on. } else { // Turn the light off. } sleep(1); } }This is the hello world program for embedded things with LEDs. 2 u/knome Apr 10 '14 since your else clause can never actually execute.uhm...#include <stdio.h> int main( int argc, char ** argv ){ unsigned int toggle = 1 ; if( (toggle = !toggle) ){ printf( "does not print\n" ); } else { printf( "does\n" ); } return 0; }...$ gcc toggle.c $ ./a.out does 1 u/wescotte Apr 10 '14 Oh duh.. reduces to if (toggle) which evaluates to false. For some reason I was thinking leftHandSide = rightHandSide always reduces to true.
3
The else clause is called when toggle is originally true. :)
toggle
To make it more clear here is a real world example.
main() { bool isOn = false; while(1) { if ((isOn = !isOn)) { // Turn the light on. } else { // Turn the light off. } sleep(1); } }
This is the hello world program for embedded things with LEDs.
2
uhm...
#include <stdio.h> int main( int argc, char ** argv ){ unsigned int toggle = 1 ; if( (toggle = !toggle) ){ printf( "does not print\n" ); } else { printf( "does\n" ); } return 0; }
...
$ gcc toggle.c $ ./a.out does
1 u/wescotte Apr 10 '14 Oh duh.. reduces to if (toggle) which evaluates to false. For some reason I was thinking leftHandSide = rightHandSide always reduces to true.
Oh duh.. reduces to if (toggle) which evaluates to false. For some reason I was thinking leftHandSide = rightHandSide always reduces to true.
View all comments
Show parent comment
4
u/[deleted] Apr 10 '14
You can toggle a switch and act on it at the same time. I actually like this one (*hides*).