Raised This Month: $ Target: $400
 0% 

Code syntax to reset variables to zero?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TinCan
Junior Member
Join Date: Nov 2007
Old 10-22-2009 , 14:28   Code syntax to reset variables to zero?
Reply With Quote #1

Trying to solve a bug in a plugin someone else made and wonder, does this one line of code set g_votes[0], g_votes[1] and g_votes[2] to zero?
g_votes[0] = g_votes[1] = g_votes[2] = 0;

Or do you have to do it like:
g_votes[0] = 0;
g_votes[1] = 0;
g_votes[2] = 0;
TinCan is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-22-2009 , 14:30   Re: Code syntax to reset variables to zero?
Reply With Quote #2

They both do the same operation.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Old 10-22-2009, 14:39
Hawk552
This message has been deleted by Hawk552. Reason: stupid server errors made me double post
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-22-2009 , 14:41   Re: Code syntax to reset variables to zero?
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
They both do the same operation.
Actually, this is not quite true. The second statement stores 0 in the DAT section and pushes it onto the stack three times, whereas the first only stores it once. So the operation in assembly will be, in pseudocode (cus I'm too lazy to write it up in proper ASM):

PHP Code:
DAT
adr001 0
adr002 0
adr003 0

CODE
array=adr001
array+1=adr002
array+2=adr003 
Whereas the other will look like:

PHP Code:
DAT
adr001 0

CODE
array+2=adr001
array+1=array+2
array=array+
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-22-2009 , 14:46   Re: Code syntax to reset variables to zero?
Reply With Quote #5

I was actually referring to the result, not the actual operation.
I guess I should start choosing my words carefully.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-22-2009 , 14:32   Re: Code syntax to reset variables to zero?
Reply With Quote #6

Yes, the first statement works. What it does is this:

PHP Code:
g_votes[0] = g_votes[1] = g_votes[2] = 0
  • Step 1 -
    PHP Code:
    g_votes[2] = // let's call this statement "VOTES_2" 
  • Step 2 -
    PHP Code:
    g_votes[1] = VOTES_2 // let's call this statement "VOTES_1" 
  • Step 3 -
    PHP Code:
    g_votes[0] = VOTES_1 
At each step, the previous statement evaluates to whatever you're assigning to.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode