flat assembler
Message board for the users of flat assembler.
Index
> Main > .. Goto page Previous 1, 2 |
Author |
|
typedef 24 Dec 2012, 09:12
Code: if (serial_port_character) { //reading a port also removes the character ... }else { //reading a new character ... } ------------------------------------------------------------- if (variable) { ... variable = something; ... }else{ //variable has a different value now ... } ------------------------------------------------------------- variable--; if (variable) { //side effects ... }else{ ... } |
|||
24 Dec 2012, 09:12 |
|
baldr 24 Dec 2012, 10:17
typedef,
Second example is incorrect: Code: if (variable) { ... variable = something; ... }else{ //variable has a different value now (HOW CAN IT BE SO?!) ... } Code: if (variable) { ... variable = something; ... } if (!variable) { //variable has a different value now ... } |
|||
24 Dec 2012, 10:17 |
|
revolution 24 Dec 2012, 11:00
typedef: All three of my example are not equivalent to your posting.
The difference is that we evaluate the argument twice in my examples and only once in your examples. Any processing that changes the argument in the first if block will then recheck the argument again in the second block. The two blocks are separate processing stages based upon the result of the argument being evaluated at two different points in time, and both blocks may be processed, or just one block or none. Your posting allows the argument to be evaluated only once and the two blocks become mutually exclusive of each other. |
|||
24 Dec 2012, 11:00 |
|
Bargest 24 Dec 2012, 16:42
typedef, compare two pieces of code:
Code: variable = true; if (variable) { ... variable = false; // this line will be executed } if (!variable) { printf("Hello, world!"); // this one will be executed too } and Code: variable = true; if (variable) { ... variable = false; // this line will be executed } else { printf("Hello, world!"); // this one will NOT be executed! new value of "variable" is ignored. } Other revolution's examples have the same meaning. |
|||
24 Dec 2012, 16:42 |
|
typedef 24 Dec 2012, 23:14
Bargest wrote: typedef, compare two pieces of code: Oh Ok. I see. The problem was the OP for just mangling the code together. he didn't say those were two different code statements. I thought that's how he wrote the code in his source file, that's why I kept on bringing the ELSE keyword. |
|||
24 Dec 2012, 23:14 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.