• Welcome to Theos PowerBasic Museum 2017.

macro metastatement causes trouble when in 2 include files.

Started by Murray Ruggiero, January 18, 2011, 01:14:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Murray Ruggiero

I have a small file as follows:


#COMPILE EXE
#DIM ALL
MACRO BOOLEAN = INTEGER
MACRO TRUE = -1
MACRO FALSE = 0

#INCLUDE ONCE "WIN32API.INC"  ' include windows api calls
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_ClassTryTranslatingThis.bas"
#INCLUDE ONCE "C:\ROUGHSETSCONTAINERLAPTOP\translatedOutput\c_ClassCallThis.bas"

FUNCTION PBMAIN() AS LONG
    FUNCTION = 15
END FUNCTION       


But I find that the macros are causing trouble.  for instance, if I put the following statement in one of the included files:
INSTANCE X as BOOLEAN
I would expect the MACRO to replace the BOOLEAN by an integer.  But this doesn't happen.    So then I get the idea to put the MACRO in two places: the included file and in the main file.  But that causes a different error - I think that I'm getting the error that you would get if you defined a macro twice in the same file.
So either way it doesn't work.  If I put macro declaration in the main file, it doesn't get interpreted by the included files.  But if I put it also in the included files, its treated as an error.

What is the solution to this?
Also, the above code is generated from a translator that I am writing for VB6 to Powerbasic.  This could be useful to a lot of people who have old vb6 code that uses a lot of COM and which would be hard to port to VB.NET.
If anyone wants the code, it is open-source, and any improvements to it are welcome.

José Roca

Quote
I would expect the MACRO to replace the BOOLEAN by an integer.  But this doesn't happen.

This isn't true. There must be something else in your files.

Quote
But if I put it also in the included files, its treated as an error.

Of course. Macros can't be defined twice.

Quote
What is the solution to this?

Don't use macros for this purpose. You're going to create many conflicts.

Murray Ruggiero

It seems that if I have a file (call it FileX) which contains includes, I can have macro definitions in the first include file, and that will apply to all following include files. But if I put the macro definitions in FileX before the includes, it doesn't apply to those include files.  If true, thats a bug.

Theo Gottwald

I do not believe in such "Bug" stories. In 99,9% of all cases the bug is infront of the monitor.
I use a lot of MACROS, if there would be bugs, I'd had them before.

Just sent me your code and I'll crosscheck it. Even if i try hard, i can't tell you right now a proven bug in PB 9.05.

If you have problems with MACROS, do as Jose said and use FUNCTIONS instead.
This will make your life as a beginner more easy.