SA-MP Forums Archive
Error in macro - 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: Error in macro (/showthread.php?tid=531428)



Error in macro - Riwerry - 12.08.2014

Hello, I'm making function that will create string with lowest possible calculated index for the string (may save LITTLE amount of memory ). You can too format this string inside function, but I have problem getting error:
error 001: expected token: "-string end-"

pawn Код:
DeclareOptimiziedString("string", "Hello %s!", "Jack"); //Example usage -> this string should have 14 cells which is lowest possible

//Macro
#define DeclareOptimiziedString(%0,%1,%2) \
        new %0[IndexCount(%1, %2)] \
        format(%0, sizeof(%0), %1, %2);

//Func that calculates index of string (with format)
IndexCount(const src[], const fmat[])
{
    new
        count,
        i;

    while(i++ < strlen(fmat))
    {
     
        if(fmat[i] == '"' || fmat[i] == ',' || fmat[i] == 32)
        {
            continue;
        }
        count++;
    }
    return strlen(src) + count;
}
Thanks!


Re: Error in macro - Vince - 12.08.2014

Pawn does not support dynamic arrays. Other than that, don't treat a macro like a function. If you need to create new variables within a macro then a function is usually more appropriate.


Re: Error in macro - Riwerry - 12.08.2014

I want to create formatted string, with lowest possible memory. That means I won't use bigger numbers than it needs like new string[128];. Yeah it's not macro, I think it's inline function, becouse I want just to replace it in piece of code, where am I. And if I create something like:
pawn Код:
#define Test(%0, %1) new %0[%1];
Its working, but in code up is something bad. :\


Re: Error in macro - [XST]O_x - 12.08.2014

You can't do that.
That's like doing
pawn Код:
new something = 5;
new array[something];
Not in pawn man, not in pawn.


Re: Error in macro - Riwerry - 12.08.2014

Yeap, but then whole thing have no sense, okay thanks.