Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] How to avoid compiling some code (like #ifdef in C)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-09-10 (17:14)
From: David MENTRE <dmentre@l...>
Subject: [Caml-list] How to avoid compiling some code (like #ifdef in C)

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:
open Printf

let compile_code = false

let a () = printf "toto\n"

let _ = if compile_code then let t = 1 in a ()

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

Does anybody see a better approach to do such a thing?

Thanks in advance,
 David Mentré <>
 GnuPG key fingerprint: A7CD 7357 3EC4 1163 745B  7FD3 FB3E AD7C 2A18 BE9E

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: