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 TAA03264; Wed, 10 Sep 2003 19:14:08 +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 TAA25369 for ; Wed, 10 Sep 2003 19:14:05 +0200 (MET DST) Received: from mwinf0104.wanadoo.fr (smtp8.wanadoo.fr [193.252.22.30]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8AHE5f21694 for ; Wed, 10 Sep 2003 19:14:05 +0200 (MET DST) Received: from oops (ARennes-303-1-32-158.w81-248.abo.wanadoo.fr [81.248.98.158]) by mwinf0104.wanadoo.fr (SMTP Server) with ESMTP id 1B94A1BFFF5A for ; Wed, 10 Sep 2003 19:14:05 +0200 (CEST) Received: from david by oops with local (Exim 3.35 #1 (Debian)) id 19x8Xc-0000SZ-00 for ; Wed, 10 Sep 2003 19:14:04 +0200 To: caml-list@inria.fr Subject: [Caml-list] How to avoid compiling some code (like #ifdef in C) From: David MENTRE Organization: none Date: Wed, 10 Sep 2003 19:14:04 +0200 Message-ID: <87llswpnvn.fsf@linux-france.org> User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; dmentre:01 --begin--:01 printf:01 printf:01 toto:01 'let:01 ocamlopt:01 dmentre:01 ifdef:01 ifdef:01 ocaml:01 mentre:01 mentre:01 compile:02 compile:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, 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. I'm thinking of using the following approach: --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? I'm using ocamlopt for compiling my code. Judging from generated assembly file, it seems to me that if compile_code is false, the code corresponding to the then part is not generated. Can anybody confirm this? Does anybody see a better approach to do such a thing? Thanks in advance, Yours, david -- David Mentré http://www.linux-france.org/~dmentre/david-mentre-public-key.asc GnuPG key fingerprint: A7CD 7357 3EC4 1163 745B 7FD3 FB3E AD7C 2A18 BE9E ------------------- 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