Raised This Month: $ Target: $400
 0% 

Using (un-identified) blocks inside functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
commonbullet
Veteran Member
Join Date: Oct 2005
Old 04-18-2006 , 10:46   Using (un-identified) blocks inside functions
Reply With Quote #1

I didn’t see it in documentation, and I haven’t seen that in any plugin. It doesn’t show any warnings in compilation, so I suppose it works fine for cleaning variables that will not be used in the rest of function.
I know they can always be broken into two or more functions, I just wondered if it’s ok in Pawn…

Crap example:
Code:
test(){     new line[72]     {         new filepath[67], len         get_configsdir( filepath , 66 )         format(filepath , 66 , "%s/maps.ini", filepath)         read_file (filepath, 2, line, 71, len)     }     // […] }
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
Basic-Master
Veteran Member
Join Date: Apr 2005
Location: hello pm
Old 04-18-2006 , 14:36  
Reply With Quote #2

maybe you should set len to something, your format call looks terrible (gasp, the entire code snippet looks awful). use something like that:
Code:
test() {   new tmp[32] // should be enough   new file[41] // the filename   new len // the length of the read line   get_configsdir(tmp, 31) // get the directory   format(file, 40, "%s/maps.ini", tmp)   read_file(file, 2, line, 31, len)   // ... }

edit: but yes, theoretically you could use blocks there..
Basic-Master is offline
Send a message via ICQ to Basic-Master Send a message via MSN to Basic-Master
commonbullet
Veteran Member
Join Date: Oct 2005
Old 04-18-2006 , 15:04  
Reply With Quote #3

thanks,

well the example was terrible and wrong (len...)
but tell me is it a bad practice to use blocks like these?
- just noted I could make less memory usage in some parts of my code...
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-18-2006 , 15:27  
Reply With Quote #4

Quote:
Originally Posted by commonbullet
thanks,

well the example was terrible and wrong (len...)
but tell me is it a bad practice to use blocks like these?
- just noted I could make less memory usage in some parts of my code...
shouldn't be a problem to do that; except that it look pretty awful to my eyes although I guess it won't have a very strong effect, unless you are allocating a lot of memory on the stack.
__________________
hello, i am pm
PM is offline
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 05:04.


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