Am Sonntag, den 04.09.2011, 11:22 -0400 schrieb John Carr: > I am working with a file format the contains 32 bit integers. > I need to use int32 on 32 bit systems. I would like to use plain > integers, unboxed and with native machine operations, on 64 bit > systems. > > Is there any way to convince ocamlopt to choose between int and > int32 representations _at compile time_?
The Netnumber module of Ocamlnet actually does this: https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mli https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mlp Netnumber is fairly standalone, so you could just copy it to your project if you don't want all of Ocamlnet. Gerd > > I could use first class modules to select implementations at > runtime, which is not worth the code complexity and still > requires an indirect function call to add numbers. I could > conditionally compile different files depending on word size, > which strikes me as an ugly and fragile solution. > > I want to be able to write "int32" and have that be compiled > like an ordinary integer type if 32 bits and tag fit into a > word, and as a boxed type otherwise. (The compiler could > mask off excess precision if desired.) Is there a reason ocaml > can't provide this? > > Another implementation would have each instance of an int32 or > int64 be boxed or not depending on whether the value fits into > a word. I don't know whether this would be faster or slower in > practice. There is a tradeoff between allocations and > conditional branches. > > --John Carr ([email protected]) > -- ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany [email protected] Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de *** Searching for new projects! Need consulting for system *** programming in Ocaml? Gerd Stolpmann can help you. ------------------------------------------------------------ -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
