From: Markus Mottl <markus@oefai.at>
To: David MENTRE <dmentre@linux-france.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to avoid compiling some code (like #ifdef in C)
Date: Wed, 10 Sep 2003 19:31:21 +0200 [thread overview]
Message-ID: <20030910173121.GB16546@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <87llswpnvn.fsf@linux-france.org>
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
next prev parent reply other threads:[~2003-09-10 17:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-10 17:14 David MENTRE
2003-09-10 17:31 ` Markus Mottl [this message]
2003-09-11 15:30 ` Xavier Leroy
2003-09-11 16:28 ` Richard Jones
2003-09-12 12:15 ` David MENTRE
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030910173121.GB16546@fichte.ai.univie.ac.at \
--to=markus@oefai.at \
--cc=caml-list@inria.fr \
--cc=dmentre@linux-france.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox