Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - -d<x> define macro <name>[=<text>] http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 -D<x>               Define macro <name>[=<text>]
------------------------------------------------------------------------------
 Syntax
   -D<macroname>[=<macrovalue>]

 Arguments
   <macroname> is a unique symbol that identifies the macro.
   <macrovalue> is an optional token sequence that, if given, replaces all
      occurrences of macroname in the source text.

 Default
   None.

 Description
   The -D switch allows defining macros from the command line,
   similarly to the #define directive in a program. Amongst others, this
   is useful for programs that contain conditional compile statements
   which then allow to create different versions of the program.

   The command line may contain several -D options, if necessary.
   The <macrovalue> argument can be a string literal surrounded with the
   "" or '' string delimiters (embedded spaces and strings are allowed).

 Example
   . Define the macro TEST without a value
   
     force.exe -DTEST test.prg
   
   . Define the macro TEST with a numeric value of 1
   
     force.exe -DTEST=1 test.prg
   
   . Define the macro TEXT with a char value of "hello"
   
     force.exe -DTEXT="hello" test.prg
   
   . Define two macros
   
     force.exe -DTEXT="hello" -DTEST=1 test.prg
   
   
   The example program below demonstrates a method to produce various
   versions of an application by placing conditional compilation
   directives in the source, and by invoking the compiler with various
   command line macro definitions.
   
   Compilation examples for the code below:
   
   . Create an unknown language version without debug code and without
     runtime limitation.
   
     force.exe test.prg
   
   . Create an English version without debug code, and without runtime
     limitation.
   
     force.exe -DENGLISH test.prg
   
   . Create a German version with debug code and a runtime limitation
     of 20 minutes.
   
     force.exe -DGERMAN -DRUN_TIME=20 -DDEBUG test.prg
   
   
   #include system.hdr
   #include screen.hdr
   #include color.hdr
   #include string.hdr
   
   #pragma W_FUNC_PROC-
   
   #ifdef ENGLISH
      #define MSG1 "Hello world"
   #else
      #ifdef GERMAN
         #define MSG1 "Hallo Welt"
      #else
         #output No language specified
         #define MSG1 "Wrdl Brmpf"
      #endif
   #endif
   
   #ifdef DEBUG
      #output Compiling debug version
      #include memory.hdr
      // Later in the program, we output additional information,
      // when DEBUG is defined.
   #endif
   
   #ifndef RUN_TIME
      // This macro specifies the time (in minutes), the program should run
      // before termination (or 0 for unlimited). This is handy to create
      // demo versions of an application.
      #define RUN_TIME 0
   #endif
   
   vardef static
      char  cMsg     := MSG1
      uint  nDemoRun := RUN_TIME
      ulong nSecEnd
   enddef
   
   proc CheckDemo static
   // Check if demo version expired
   if nDemoRun .and. seconds() > nSecEnd
      alert( "Demo run was limited to " + istr( nDemoRun ) + " minutes.;" + ;
         "The application will now terminate.", " OK ", RED_WHITE, BLUE_WHITE )
      quit
   endif
   endproc
   
   proc main
   if nDemoRun                  // if demo version
      nSecEnd := seconds() + 60 * RUN_TIME // set time of expiration
   endif
   ? cMsg                       // display internationalized message
   #ifdef DEBUG
   ? coreleft()                 // show free memory if debug version
   #endif
   nSecEnd -= 60 * RUN_TIME + 1 // simulate the passing time for this example
   wait "Application is running..."
   CheckDemo() // place this call in the main loop of the application
   wait "Application terminate normally..." // not executed in demo version
   endproc

See Also: #define

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson