Code:
#DEBUG ERROR ON '*** Macro is a powerful text substitution construct that may take a single-line or multi-line format. '*** ---> IMPORTANT POINT ---> It generates absolutely no executable code unless it is referenced '*** '*** '*** For this example I will assume I recompile over and over and just change the equates value of %DODEBUG = something '*** %DODEBUG = 0 'Debug Mode is Off '*** %DODEBUG = 1 'Debug Mode is On '*** %DODEBUG = 2 'Debug Mode is Only on, if some GPF is about to occur, and want to find it and fix it '*** '*** '*** Uncomment any of the 3 tests you want to check results %DODEBUG = 0 'Debug Mode is Off '%DODEBUG = 1 'Debug Mode is On '%DODEBUG = 2 'Debug Mode is Only on, if some GPF is about to occur, and want to find it and fix it MACRO DoMessage(p1, pMode) '<--- Variables do not need to be declared??? (So how do I know what p1, and pMode are???..... Best guess p1 = pointer, pMode = Type of pointer? (varptr or strptr)???
Code:
FUNCTION test() AS LONG LOCAL p1 AS LONG LOCAL p2 AS STRING ' DoMessage("", "") p1 = 42 p2 = "The Answer is" MSGBOX "%DODEBUG = 0" + p1 + p2 p1 = 65535 FUNCTION = p1 END FUNCTION
Code:
MACROTEMP T '<--- Never gets used so not refereced (see IMPORTANT POINT)
Code:
#IF %DEF(%DODEBUG) = 0 '<--- %DEF must be used to test if the equates is correct
Code:
MSGBOX "%DODEBUG = 0" + p1 + pmode #DEBUG PRINT "%DODEBUG = 0" p1 = 65535 #ELSEIF %DEF(%DODEBUG) = 1 '<--- %DEF must be used to test if the equates is correct MSGBOX "%DODEBUG = 1" #DEBUG PRINT "%DODEBUG = 1" #ELSEIF %DEF(%DODEBUG) = 2 '<--- %DEF must be used to test if the equates is correct MSGBOX "%DODEBUG = 2" #DEBUG PRINT "%DODEBUG = 2" #ENDIF END MACRO '*** Function to test the macro '<--- Never got used, so I referenced it for testing FUNCTION test() AS LONG LOCAL p1 AS LONG LOCAL p2 AS STRING ' DoMessage("", "") '<--- Making this reference should result in the following p1 = 42 p2 = "The Answer is" DoMessage(p1, p2) '<--- Making this reference should result in the following '<--- Function never returns a value (but minor point for this test) :-) '---> To Me p1 should now be 65535 because I changed it in the macro, but its not????
Code:
FUNCTION = p1 END FUNCTION '*** Compiling without this will result in 'PowerBASIC for Windows 'PB/Win Version 9.01 'Copyright (c) 1996-2009 PowerBasic Inc. 'Venice, Florida USA 'All Rights Reserved ' 'Primary source: I:\POWERB~4\HELPOT~1\MACROS~1\Macros2.bas {29 total lines} 'Target compilation: Macros2.exe 'Compile time: 0.1 seconds, at 34800 lines/minute ' '460 bytes compiled code, 1576 bytes RTLibrary, '0 bytes string literals, and 1872 bytes dgroup. 'Executable stack size: 1048576 bytes. 'Disk image: 5120 bytes Memory image: 3448 bytes. ' 'Component Files: '---------------- 'I:\POWERB~4\HELPOT~1\MACROS~1\Macros2.bas '============================== 'Compile succeeded at 6:25:18 PM on 5/6/2009 ' 'PowerBASIC for Windows 'PB/Win Version 9.01 'Copyright (c) 1996-2009 PowerBasic Inc. 'Venice, Florida USA 'All Rights Reserved ' 'Error 504 in I:\POWERB~4\HELPOT~1\MACROS~1\Macros2.bas(0:000): Executable requires WinMain/PBMain function '============================== 'Compile failed at 6:47:04 PM on 5/6/2009 '*** So I added it to compile FUNCTION PBMAIN () AS LONG LOCAL Results AS LONG Results = Test '<<< Calling this in turn makes a reference to the macro, which in turn expands and inserts the macro code into the "Test" function at compile time MSGBOX STR$(Results) END FUNCTION
Leave a comment: