Modules, conditional compilation, external constants
Posted: Mon Jul 01, 2013 12:18 am
Suppose I want to compile different code inside a module, depending on a external constant value.
Normally I would put the configuration constants in one include.
for example: #lib_debug = 1
If #lib_debug = 1 I want to compile the debug version, else the release version.
The code above can't be compiled because the constant is not accessible.
Note all the constants inside residents are accessible so there is also some kind of disparity here.
Nevertheless, what could be a good solution to implement what described above ? I would like to keep those configuration constants in the include, they are a very straightforward solution to configure an entire library setting some values from a single point included everywhere.
Transform them too into a module to be referred everywhere ? SIGH
EDIT: updated with a better example here -> http://www.purebasic.fr/english/viewtop ... 99#p416699
Still unsolved.
EDIT: solved with BETA 5 thanks to the addition of the #PB_Module constant for the 'Defined' compiler command.
Normally I would put the configuration constants in one include.
for example: #lib_debug = 1
If #lib_debug = 1 I want to compile the debug version, else the release version.
Code: Select all
; this is inside libconfig.pbi
#lib_debug = 0
; this is a module of the library, includes libconfig.pbi
DeclareModule test
Declare proc()
EndDeclareModule
Module test
Procedure proc()
; common code start
CompilerIf #lib_debug = 0
; release code
CompilerElse
;debug code
CompilerEndIf
; common code end
EndProcedure
EndModule
The code above can't be compiled because the constant is not accessible.
Note all the constants inside residents are accessible so there is also some kind of disparity here.
Nevertheless, what could be a good solution to implement what described above ? I would like to keep those configuration constants in the include, they are a very straightforward solution to configure an entire library setting some values from a single point included everywhere.
Transform them too into a module to be referred everywhere ? SIGH
EDIT: updated with a better example here -> http://www.purebasic.fr/english/viewtop ... 99#p416699
Still unsolved.
EDIT: solved with BETA 5 thanks to the addition of the #PB_Module constant for the 'Defined' compiler command.