Supermacros
#1

Hi! I'm using Zeex's compiler, and I'm trying to create a "supermacro" of sorts:
main.pwn
pawn Код:
#include "macro"
#include "macro"
macro.inc
pawn Код:
#if defined MACRO_END
    #endinput
#endif

#if !defined MACRO_HEADER
    #define MACRO_HEADER
    print("Hello 1!");
    #endinput
#endif

print("Hello 2!");
#define MACRO_END
But it includes both "versions" at once. I debugged it with:

main.pwn
pawn Код:
#include "macro"
macro.inc
pawn Код:
#if defined MACRO_END
    #endinput
#endif

#if !defined MACRO_HEADER
    #define MACRO_HEADER
    print("Hello 1!");
    #endinput
#endif

#error But I only included it once :(
#define MACRO_END
It errors out even when included only once.
Any idea how to approach this?
Reply
#2

I have experienced this issue before, but I was just doing a quick check for you and I am unable to test at the moment, but ****** had given some examples of ways he does his custom include guards.

https://github.com/Zeex/pawn/issues/107

Not sure if this is helpful, I am not able to check at this time.
Reply
#3

I know, but I'm not using compat mode so include guards are not in place. It's an issue with preprocessor second pass (the reason why ALS hooks work at all).
Reply
#4

I found a way around it, but really is kinda poor one.

Код:
#if defined _INC_MACRO
    #endinput
#endif

#if !defined _INC_MACRO
printf();
#endif

#define _INC_MACRO
Wrapping the code within an #if statement it seems to work no matter how many times you include it. I don't know if you'll use it or will still to try and find a better solution.
Reply
#5

Have you tried it with the Russian compiler?
Reply
#6

It appears only functions are effected by this, stocks/publics are all fine when being within a defined #if statement.

Unless you don't call the stock within the #if statement, it causes issues.

So the calling of natives/stocks/functions/callbacks are the issue here.
Reply
#7

It seems the russian compiler is using compat mode by default, so it includes include guards and won't include the file the second time.

@azzerking: IF you add #error on the bottom of the file, even if you include the file once it'll error out. Not much different than code I posted in the first post.
Reply
#8

Quote:
Originally Posted by Misiur
Посмотреть сообщение
It seems the russian compiler is using compat mode by default, so it includes include guards and won't include the file the second time.

@azzerking: IF you add #error on the bottom of the file, even if you include the file once it'll error out. Not much different than code I posted in the first post.
I'm going through the source code, see if I can find a work around. If I post back I found one, if not I didn't
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)