From function to Macro
#1

I made a function , but i need it as a macro ...

pawn Код:
Checkx(string[])
{
    if(!strcmp(string,"Drive",true) || !strcmp(string,"Fly",true)) return 1;
    return 0;
}
This is good , but if i try to make it macro ... :

pawn Код:
#define Checkx(%0) if(!strcmp(%0,"Drive",true) || !strcmp(%0,"Fly",true)) return 1; else return 0;
I get errors ...
Reply
#2

pawn Код:
#define Checkx(%0) return !strcmp(%0, "Drive", true) || !strcmp(%0, "Fly", true);
Try this, maybe it will work
Reply
#3

somebody else ?
Reply
#4

Try this
Код:
#define Checkx(%0) (!strcmp(%0, "Drive", true) || !strcmp(%0, "Fly", true)) ? 1 : 0;
Reply
#5

Quote:
Originally Posted by Jefff
Try this
Код:
#define Checkx(%0) (!strcmp(%0, "Drive", true) || !strcmp(%0, "Fly", true)) ? 1 : 0;
It depends on this func. usage.
Reply
#6

Use #

#%0

I recommend starting from %1 in defines though.


EDIT: Oh, so that wasn't the problem. Uhm, defines can only use one " if() something; "
Why don't you just keep the function and make it like this then:

Код:
#define Checkx(%1); FunctionCheckx(#%1);

Checkx(noob);
Well you get the idea..
Reply
#7

pawn Код:
#define Checkx(%0) (!strcmp(%0, "Drive", true) || !strcmp(%0, "Fly", true))
Reply
#8

cant use spaces in a define do:

#define funcx \
funcwhatitdoes
Reply
#9

Can't use spaces in the pattern - Checkx(%0), but can in the replacement part - check it.
Reply
#10

pawn Код:
#define Checkx(%0) \
    (!strcmp((%0),"Drive",true)) || (!strcmp((%0),"Fly",true))
Try it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)