caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] How to avoid compiling some code (like #ifdef in C)
@ 2003-09-10 17:14 David MENTRE
  2003-09-10 17:31 ` Markus Mottl
  2003-09-11 15:30 ` Xavier Leroy
  0 siblings, 2 replies; 5+ messages in thread
From: David MENTRE @ 2003-09-10 17:14 UTC (permalink / raw)
  To: caml-list

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é <dmentre@linux-france.org>
   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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-09-12 12:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-10 17:14 [Caml-list] How to avoid compiling some code (like #ifdef in C) David MENTRE
2003-09-10 17:31 ` Markus Mottl
2003-09-11 15:30 ` Xavier Leroy
2003-09-11 16:28   ` Richard Jones
2003-09-12 12:15   ` David MENTRE

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).