Author: Steffen Jakob
Date: 01:01:23 07/22/02
Go up one level in this thread
On July 21, 2002 at 21:36:53, Miguel A. Ballicora wrote: > >>1)How do I add a code with compiler switch? >> >you define a variable like this: > >#define HASH_PRUNE > >and then you do > > >#if defined(HASH_PRUNE) > code_1(); >#else > code_2(); >#endif > >code_1() is compiled and NOT code_2(). Also valid options are > >#ifdef HASH_PRUNE > code_1(); >#else > code_2(); >#endif > >or > >#if defined(HASH_PRUNE) > optional_code(); >#endif The problem with that approach is that you actually have two different programs. If you work for a long time with a switch enabled its likely that your code wont compile if you disable the switch. A better solution in many cases is to use a const boolean expression. You favourite compiler will skip the code if the expression is false. Example: const bool HASH_PRUNE = true; if (HASH_PRUNE) { code_1(); } else { code_2(); } This doesnt work of course if you want to modify structs depending on such a const. Greetings, Steffen.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.