A question about tagged functions
#1

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);
Reply
#2

******, 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.
Reply
#3

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.
Reply
#4

Yeah, thought so. Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)