Is it correct to assume that conditional compilation should be addressed apprioriately if a #define appears in another module?
One of my programs has a #define in the "header" file, but the other modules don't see it. Obviously it's easy to add them to each file, but that partially defeats the purpose...
#define needs to be local?
It depends what you are using the #defines for.
If it is a constant (or an expression that evaluates to a constant) then you are probably best served by using a Const.
If you are writing conditional code using #ifdef then you can define global definitons to the compiler by using the -D option. You can also "undefine" values using -U option. These options are probably best placed in the project control file.
Another method is to put the #defines in a single file and then use the #include directive (just like C) to import the definitions into the other source file.
If it is a constant (or an expression that evaluates to a constant) then you are probably best served by using a Const.
If you are writing conditional code using #ifdef then you can define global definitons to the compiler by using the -D option. You can also "undefine" values using -U option. These options are probably best placed in the project control file.
Another method is to put the #defines in a single file and then use the #include directive (just like C) to import the definitions into the other source file.
Mike Perks
Re: #define needs to be local?
Not with respect to its use in a #ifdef or #if defined() construct. The scope of a #define extends from the point at which it appears in a module to the end of the module unless it is undefined in between using #undef.pjc30943 wrote:Is it correct to assume that conditional compilation should be addressed apprioriately if a #define appears in another module?
As Mike suggested, the way to create a "global" #define is to use the -D command line option (typically placed in the .pjt file). If it is placed in the .pjt file, the scope of that definition covers all of the modules appearing after it in the .pjt unless there is an intervening -U to undefine the symbol. The same order applies for -D/-U that appear on the command line.
Consider the .pjt file excerpt below. When mod1.bas and mod2.bas are compiled, #if defined(WITH_DEBUG) will be true. Note, however, that if there is an #undef WITH_DEBUG in mod1.bas, the symbol will be undefined from the line at which it is undefined through the end of the mod1 only. It will still be defined for mod2.bas unless it is also undefined there. The symbol WITH_DEBUG will not be defined in mod3.bas unless it is defined therein.
Code: Select all
-DWITH_DEBUG
mod1.bas
mod2.bas
-UWITH_DEBUG
mod3.bas
Code: Select all
#define WITH_DEBUG
Public Const WithDebug as Boolean = CBool(WITH_DEBUG)
- Don Kinzer