[Question]Define in define
#1

There are any way to use defines in define? For example:
pawn Код:
#define one       #if !defined two #error...
So in that way, I could check entered parameters doesn't dublicated for some setup functions during compile time. Or there are any other way to do this?
Reply
#2

Could you explain again ?
Reply
#3

I think he's trying to say that if he can put 2 defines in 1 but i think thats not possible.
Reply
#4

Maybe you mean
pawn Код:
#if defined one && !defined two
    #define xyz
#endif
or
pawn Код:
#if defined two
    #define one
#endif
Reply
#5

From what I understood it would be like this:

PHP код:
#if defined one
    #define two
#else
    #define one
#endif 
Reply
#6

Quote:
Originally Posted by Scottas
Посмотреть сообщение
There are any way to use defines in define? For example:
pawn Код:
#define one       #if !defined two #error...
So in that way, I could check entered parameters doesn't dublicated for some setup functions during compile time. Or there are any other way to do this?
Yes it is

Examples:
pawn Код:
#define RED 0xFF0000FF
#define invalidid SendClientMessage(playerid, RED, "This Player ID is not connected.");
pawn Код:
#define SetVehicleNumberPlateF(%0,%1,%2); UseBrackets\
    {\
    new formatstring[32];\
    format(formatstring,sizeof(formatstring),%1,%2);\
    SetVehicleNumberPlate(%0,formatstring);\
    }

#define UseBrackets if(negative != positive)
new bool:negative = false, bool:positive = true;
As you can see that I've used defines inside the defines.
But if you write the same define text into it's own define so the compiler will crash.

Example:
pawn Код:
#define fail_defined_variable fail_defined_variable //It loops around and there is no end
new fail_defined_variable;
In the worst case after compiling it you have to close pawncc.exe from taskmanager.
Reply
#7

Well, I'll give a better example :
pawn Код:
// Some kind of function:
#define AddSymbol(%0)

// Then use this function
AddSymbol(SYMBOL_ONE);
AddSymbol(SYMBOL_TWO);
AddSymbol(SYMBOL_THREE);
What I am trying to do, is to make that compiler would give an error, if you enter the same symbol twice, like:
pawn Код:
// Then use this function
AddSymbol(SYMBOL_ONE);
AddSymbol(SYMBOL_TWO);
AddSymbol(SYMBOL_THREE);
AddSymbol(SYMBOL_TWO);
In this case, function AddSymboll should contain something like:
pawn Код:
#define AddSymbol(%0) #if defined SYMBOL_%0 #error Symbol already exists #endif
But function like that wont compile, it gives error. So all I want to know, is it possible to make something like that?
Reply
#8

Just use a stock

pawn Код:
#define AddSymbol(%0) stock %0

AddSymbol(SYMBOL_ONE);
AddSymbol(SYMBOL_TWO);
AddSymbol(SYMBOL_THREE);
AddSymbol(SYMBOL_TWO);
Reply
#9

I am trying to add a field into sqlite database, and instead of getting table info and checking if field already exists, I want make something what I've tried to explane.

Nero, thanks. I haven't thought about this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)