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 RAA18053; Thu, 11 Sep 2003 17:31:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA28337 for ; Thu, 11 Sep 2003 17:31:06 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8BFUxf21349; Thu, 11 Sep 2003 17:30:59 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA20741; Thu, 11 Sep 2003 17:30:56 +0200 (MET DST) Date: Thu, 11 Sep 2003 17:30:56 +0200 From: Xavier Leroy To: David MENTRE Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to avoid compiling some code (like #ifdef in C) Message-ID: <20030911173056.A29749@pauillac.inria.fr> References: <87llswpnvn.fsf@linux-france.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <87llswpnvn.fsf@linux-france.org>; from dmentre@linux-france.org on Wed, Sep 10, 2003 at 07:14:04PM +0200 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 --begin--:01 printf:01 printf:01 toto:01 'let:01 ocamlopt:01 ocamlc:01 camlp:01 type-checked:01 type-checked:01 ifdef:01 toplevel:01 checking:01 preprocessor:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > --begin-- > open Printf > > let compile_code = false > > let a () = printf "toto\n" > > let _ = if compile_code then let t = 1 in a () > --end-- > > In above code, if compile_code is true, then the auto-test is executed, > otherwise not. But if compile_code is false, is the code corresponding > to 'let t = 1 in a ()' generated? With ocamlopt, that code is eliminated as part of constant propagation. With ocamlc, the code of "let t = 1 in a()" is generated. > Does anybody see a better approach to do such a thing? Others mentioned preprocessing with the tool of your choice. Camlp4 can do #ifdef-style conditional compilation, but in a pinch you can even use cpp as your preprocessor. Whether this is a "better" approach is open to debate. With a preprocessor, you can remove not just code for expressions, but also other kind of code, e.g. code for the toplevel binding "let a() = ...". So, you get more flexibility, but at the expense of less static checking. In particular, code that is #ifdef-ed out is not type-checked, while it is type-checked in your solution above. - Xavier Leroy ------------------- 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