Unsigned integers

I’m binding a C library (nbdkit / libnbd · GitLab) which deals with 32 and 64 bit offsets and sizes, and it seems like a case where unsigned types are genuinely necessary. I actually had a bug reported where the C library is returning an array of uint32_t (nbd_block_status - send block status command to the NBD server) and I had (wrongly) converted this to an array of int32, and code failed when it interpreted some numbers as negative.

I see there seem to be two candidate libraries for handling unsigned ints:

Not a lot to choose between them, both projects seem to be actively maintained and both would do what I want. ocaml-integers seems simpler which might be an advantage.

So my questions are:

Is there an obvious choice for library for unsigned ints? I only really need uint32 and uint64.

Is this something that might be added to the standard library/runtime one day?

See the discussion at Unsigned 32-bit and 64-bit integers by yallop · Pull Request #1201 · ocaml/ocaml · GitHub, especially Unsigned 32-bit and 64-bit integers by yallop · Pull Request #1201 · ocaml/ocaml · GitHub.

Cheers,
Nicolas

3 Likes