A question about tagged functions - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (
https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: A question about tagged functions (
/showthread.php?tid=425970)
A question about tagged functions -
Joey^ - 27.03.2013
So I found out that you can have functions with a tag, for example:
pawn Код:
Float:square(Float:a)
return (a * a);
But if you compile this, the compiler will print out a warning:
Код:
: warning 208: function with tag result used before definition, forcing reparse
Then I found out that you have to use forward before the function, so:
pawn Код:
forward Float:square(Float:a);
Float:square(Float:a)
return (a * a);
And now, the compiler will compile normally without any warnings. So, my question is: is it any better by using tagged functions or is it the same by using plain functions like this:
pawn Код:
square(Float:a)
return (a * a);
Re: A question about tagged functions -
Joey^ - 27.03.2013
******, thank you very much by explaining me this. I understand some things clearly now.
I've got one more question about parameters in the functions. Is it a big difference when using const with some parameters and not using?
For example:
pawn Код:
printMessage(const message[])
return printf("%s", message);
printMessage(message[])
return printf("%s", message);
Is there some kind of difference between those two codes? Expect that when using const that variable/parameter can't be changed in the function.
Re: A question about tagged functions -
Sinner - 27.03.2013
Quote:
Originally Posted by Joey^
******, thank you very much by explaining me this. I understand some things clearly now.
I've got one more question about parameters in the functions. Is it a big difference when using const with some parameters and not using?
For example:
pawn Код:
printMessage(const message[]) return printf("%s", message);
printMessage(message[]) return printf("%s", message);
Is there some kind of difference between those two codes? Expect that when using const that variable/parameter can't be changed in the function.
|
const (Constant) means you can't alter the parameter. You're using a string so since you're actually passing a pointer to the address the first elemt of the string is located at rather than a copy of the variable (like you would with integers or floats) it would be possible to change the string. const prevents this.
So for example, doing:
pawn Код:
stock afunction(const string[]) {
string[0] = '_';
}
Would give you an error, since you can't alter constant parameters.
pawn Код:
must be lvalue (non-constant)
Hope that helped.
Re: A question about tagged functions -
Joey^ - 27.03.2013
Yeah, thought so. Thanks guys.