Error in macro
#1

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!
Reply
#2

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)