Browse thread
[Caml-list] How to avoid compiling some code (like #ifdef in C)
-
David MENTRE
- Markus Mottl
- Xavier Leroy
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Markus Mottl <markus@o...> |
| Subject: | Re: [Caml-list] How to avoid compiling some code (like #ifdef in C) |
On Wed, 10 Sep 2003, David MENTRE wrote:
> In my OCaml program, I want to make the _compilation_ (and not simply
> execution) of some part of the code optional (some internal auto-tests
> for example), depending on some configuration option.
>
> In C, I would use an #ifdef for this.
In OCaml you can either also use the C-preprocessor or the preprocessor
camlp4, e.g. (using OCamlMakefile for specifying the preprocessor in
the topmost comment):
---------------------------------------------------------------------------
(*pp camlp4o pa_macro.cmo *)
open Printf
DEFINE Compile_code
let a () = printf "toto\n"
let _ =
IFDEF Compile_code
THEN
let t = 1 in a ()
ELSE
()
END
---------------------------------------------------------------------------
Or as usual with cpp:
---------------------------------------------------------------------------
(*pp cpp *)
open Printf
#define Compile_code
let a () = printf "toto\n"
let _ =
#ifdef Compile_code
let t = 1 in a()
#else
()
#endif
---------------------------------------------------------------------------
Regards,
Markus Mottl
--
Markus Mottl http://www.oefai.at/~markus markus@oefai.at
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners