caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: Gao katie <katiegao@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] newbie question: How to do conditional compilation?
Date: Tue, 18 Sep 2001 10:06:27 +0200	[thread overview]
Message-ID: <20010918100627.C22805@verdot.inria.fr> (raw)
In-Reply-To: <20010918040228.8243.qmail@web10102.mail.yahoo.com>; from katiegao@yahoo.com on Mon, Sep 17, 2001 at 09:02:28PM -0700

Hi,

On Mon, Sep 17, 2001 at 09:02:28PM -0700, Gao katie wrote:

> Can anyone tell me how to do conditional compilation in Ocaml?
> #ifdef DEBUG
> ...
> #else
> ...
> #endif

1/
You can use camlp4.

Compile either with 
   ocamlc -pp "camlp4o pa_ifdef.cmo"
or with
   ocamlc -pp "camlp4o pa_ifdef.cmo -DDEBUG"

In your code, you can then use "ifdef DEBUG ... else ... end" in
position of expression, or "ifdef ... end" in position of structure
item (toplevel phrase, if you prefer). You can also use "define"
(but without parameters: "define DEBUG", not "define DEBUG xxx")

2/
Another solution is to use /lib/cpp, the C preprocessor.  I think that
you can use it in only one command with the ocamlc parameter -pp:
   ocamlc -pp "/lib/cpp"
   ocamlc -pp "/lib/cpp -DDEBUG"

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


      reply	other threads:[~2001-09-18  8:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-18  4:02 Gao katie
2001-09-18  8:06 ` Daniel de Rauglaudre [this message]

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=20010918100627.C22805@verdot.inria.fr \
    --to=daniel.de_rauglaudre@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=katiegao@yahoo.com \
    /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;
as well as URLs for NNTP newsgroup(s).