Annoying bug with #define
#1

Hi,

There is a bug in #define, or it's a limitation, and i'm desperately searching for a workaround but i believe there isn't..

EXEMPLE:
pawn Код:
#include a_samp

#define PRINT(%1) print(#%1)

public OnFilterScriptInit()
{
  PRINT("blabla"); //work, prints "blabla"
  PRINT(blabla);  //work, prints "blabla"
  PRINT(bla[3]);  //work, prints "bla[3]"
  PRINT("bla(3)"); //work, prints "bla(3)"
  PRINT(bla(3));  //don't work, weird errors when compiling
}
So this bug appear when using parenthesis in a "fake string", which is a bit annoying for what i need to do.

Any idea?
Reply
#2

Why don't you just use " " then?
Reply
#3

Because that's not what i want to do.
Reply
#4

just curious are you trying to post the literal string "bla(3)" or whatever bla(3) returns?
Reply
#5

Quote:
Originally Posted by Daren_Jacobson
just curious are you trying to post the literal string "bla(3)" or whatever bla(3) returns?
The litteral string.

My #define should print the function with arguments, then call the function itself. Like

pawn Код:
bla(value1, value2)
{
  return value1 * value2;
}

main()
{
  MYDEFINE(bla(3, 2)); //i want it to print "bla(3, 2)" and then call bla(3, 2);
}
Well, i don't think it's possible, i've tried many things without success. The best i did, using a crap workaround which is problematic for something else, is printing the function name and only the first argument.
Reply
#6

pawn Код:
#define PRINT(%1) print(#%1); %1
i think is what you want, but no clue why you can't use () in it.
Reply
#7

Quote:
Originally Posted by Daren_Jacobson
pawn Код:
#define PRINT(%1) print(#%1); %1
i think is what you want, but no clue why you can't use () in it.
Of course i knew that already, sorry if my post was unclear but thanks anyway
Reply
#8

So with your #define i have errors, but with this one
pawn Код:
#define PRINT(%1(%2)) print(#%1 "(" #%2 ")")
This work but only print the first argument so PRINT(bla(12)); will print "bla(12)", but PRINT(bla(1,2)); produce errors.

And this:
pawn Код:
#define PRINT(%1(%2)) printf(#%1 "(%s)", #%2)
compile, but still print only the first argument: PRINT(bla(1,2)); just print "bla(1)"..Weird.

So it looks like a problem with commas inside parenthesis, not parenthesis themself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)