[Tutorial] Function Type Explanation (stock, public, plain)
#7

You make it sound it sound as if a method tagged stock will hide all warnings associated with it. This is a side-effect of what an unused stock method does i.e. nothing because it's not compiled into the P-code. The Pawn compiler will still complain about warnings associated with a stock method if it is referenced in your code.

A stock method is a method that is allowed to be skipped by the parser if it's not used. In other words, you will not be warned that it is unused and it does not exist in the compiled code. A method that is not tagged stock and is also unused is still compiled into the P-code, thus using space in the compiled code.

You might ask now why doesn't the Pawn compiler just remove unused tagged stock or not to save space? One reason being because it cannot infer whether or not the method is compiled into the script for external purposes (i.e. a public method). You may have public "unused" methods that are callable by an external program.

Quote:

Basically, it's stupid to use stock functions because you can't have a function in your gamemode which you don't even use?

Код:
// start of script
main() {
    foo1(); 
    // foo2() unused, warning
}

foo1() { /* */ }
foo2() { /* */ }
// end script
Using stocks vs. not using them is more of a personal preference. I personally use stocks wherever you might use a "plain" function, dealing with unused methods/variables warnings is a hassle to me after making a massive change (I'd rather let the compiler deal with removal from compiled code).

If you want to enforce that a function MUST be used then don't use stocks. I've never had the case where a function MUST be used. I'd shoot a guess that most people making SA:MP scripts won't unless they do a lot of formal design up front and would like to be warned if they forgot to include use of a required method.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)