1

Recently I have to read some source code written in OCaml. And I start to read the source code after reading materials about OCaml. When I compile the source code, there's something wrong. The part which the compiler says wrong is below:


let b = [| 0x2; 0xc; 0xf0; 0xff00; 0xffff0000; 0x7fffffff00000000 |]


The error message says that's a integer range problem. I know that integer in OCaml range from -2^30 ~ 2^30 - 1 and Thus lead to that problem. But the source code is from a project that other people can use it. How can I compile it correctly? Can somebody tell me some details?

Falko
  • 17,076
  • 13
  • 60
  • 105
KUN
  • 527
  • 4
  • 18
  • 2
    If it is practical, you could try to patch the source to use `Int64.t` instead of `int`. Unlike `int`, `Int64.t` will have the same range across machines. – gsg Nov 08 '13 at 05:18

1 Answers1

5

Very likely the code is intended for a 64-bit OCaml system.

As gsg suggests, you could try changing 0x2 to 0x2L and so on. If you're lucky there won't be too many things to change in the code.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • Is there some compile options can let me compile it in a 32 bit system? – KUN Nov 08 '13 at 04:52
  • 1
    You need a 64-bit OCaml system. You can't make a 32-bit OCaml system act like a 64-bit one. It might be possible to build a 64-bit OCaml system for your platform, depending on what it is. But if it hasn't already been done, it will be a pretty serious project. – Jeffrey Scofield Nov 08 '13 at 05:04