From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA23360; Wed, 10 Sep 2003 19:31:26 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA28735 for ; Wed, 10 Sep 2003 19:31:24 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8AHVOT13855 for ; Wed, 10 Sep 2003 19:31:24 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.4) with ESMTP id h8AHVLqF020994; Wed, 10 Sep 2003 19:31:21 +0200 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.4) id h8AHVLZm020993; Wed, 10 Sep 2003 19:31:21 +0200 Date: Wed, 10 Sep 2003 19:31:21 +0200 From: Markus Mottl To: David MENTRE Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to avoid compiling some code (like #ifdef in C) Message-ID: <20030910173121.GB16546@fichte.ai.univie.ac.at> Mail-Followup-To: David MENTRE , caml-list@inria.fr References: <87llswpnvn.fsf@linux-france.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87llswpnvn.fsf@linux-france.org> User-Agent: Mutt/1.4.1i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 camlp:01 camlp:01 printf:01 printf:01 toto:01 toto:01 ifdef:01 ifdef:01 cmo:01 ocaml:01 ocaml:01 sep:01 mentre:01 preprocessor:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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