flat assembler
Message board for the users of flat assembler.

Index > Main > ..

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
typedef: You seem to have missed something.

if (serial_port_character) { //reading a port also removes the character
...
}
if (!serial_port_character) { //reading a new character
...
}
-------------------------------------------------------------
if (variable) {
...
variable = something;
...
}
if (!variable) { //variable has a different value now
...
}
-------------------------------------------------------------
if (variable--) { //side effects
...
}

if (!variable--) {
...
}
Post 24 Dec 2012, 00:13
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
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{
...
}    
Post 24 Dec 2012, 09:12
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
typedef,

Second example is incorrect:
Code:
if (variable) {
...
  variable = something;
...
}else{ //variable has a different value now (HOW CAN IT BE SO?!)
...
}    
isn't equivalent to
Code:
if (variable) {
...
variable = something;
...
}
if (!variable) { //variable has a different value now
...
}    
Post 24 Dec 2012, 10:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
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.
Post 24 Dec 2012, 11:00
View user's profile Send private message Visit poster's website Reply with quote
Bargest



Joined: 09 Feb 2012
Posts: 79
Location: Russia
Bargest
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.
Post 24 Dec 2012, 16:42
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Bargest wrote:
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.



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. Laughing
Post 24 Dec 2012, 23:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.