Conditional Compiles and Nesting

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Conditional Compiles and Nesting

Post by Don_Kirby »

Is suppose the heading pretty much says it all. Can I nest conditional compiler directives?

Code: Select all

#IfDef Something
'compile this code
#IfDef SomethingElse
'Compile more code
#EndIf
#EndIf


-Don
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

Yes you can. If you are not sure you can always use the --list compiler option to look at the compiler listing file and you can see what it included.

You can define a conditional symbol either in your source code with a #define or using the compiler -D option.
Mike Perks
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

mikep wrote:You can define a conditional symbol either in your source code with a #define or using the compiler -D option.
I have been using the #Define keyword in the IDE, but I've run into a snag. One of my conditional compiles puts the application into a speed test mode, where a few global counter variables are declared, and various tasks add to the counters on each loop. The data is then output via Com1. The problem is that the #define keywords are module level, and I need it to be global.

What's the suggested method to implement a global conditional define, bearing in mind that I'm not using the command line compiler? Is it possible to define in the project file?


-Don
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Don_Kirby wrote:Is it possible to define in the project file?
Yes. In addition to naming the project files, you can place nearly any command line option. This is documented in the description of a project file: http://www.zbasic.net/doc/ZBasicRef.php?page=100

Code: Select all

-Dfoo=bar
file1.bas
file2.bas
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

I'm not sure if it's documented or not, but you can also comment out lines in the project file, using the same character ( ' ) as in the IDE. This is very useful for the conditional compile defines.

-Don
Post Reply