Variable Argument Functions[QUESTION] - 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)
+--- Thread: Variable Argument Functions[QUESTION] (
/showthread.php?tid=306636)
Variable Argument Functions[QUESTION] - T0pAz - 27.12.2011
How to do this in PAWN?
Код:
int Numbers::addNumbers(int n, ...)
{
va_list args;
int sum = 0;
va_start(args, n);
for (int x=0; x<n; x++)
{
sum += va_arg(args, int);
}
va_end(args);
return sum;
}
Re: Variable Argument Functions[QUESTION] -
THE_KNOWN - 27.12.2011
pawn Код:
stock addNumbers(n, ...)
{
new args = numargs();
new sum = n;
for(new i;i<args;i++)
{
sum += getarg(i,0);
}
return sum;
}
not sure.. should be it
AW: Variable Argument Functions[QUESTION] -
Nero_3D - 27.12.2011
Remove the n and you should be fine
pawn Код:
stock addNumbers(...) {
new
sum = 0,
num = numargs();
while(--num != -1) {
sum += getarg(num, 0);
}
return sum;
}
Re: Variable Argument Functions[QUESTION] - T0pAz - 27.12.2011
Thank you both. Deserve reputation.