package containers

  1. Overview
  2. Docs
On This Page
  1. Bit Field
Legend:
Library
Module
Module type
Parameter
Class
Class type

Bit Field

This module defines efficient bitfields up to 30 or 62 bits (depending on the architecture) in a relatively type-safe way.

module B = CCBitField.Make(struct end);;

#install_printer B.pp;;

module X = (val B.int ~name:"x" ~width:3 ());;
module Y = (val B.int ~name:"y" ~width:2 ());;
module Z = (val B.bool ~name:"z" ());;

let f = B.empty |> X.set 3 |> Y.set 1;;

Z.get f ;;

f |> Z.set true |> Z.get ;;

Format.printf "f: %a@." B.pp f;;

status: experimental

  • since 0.13
exception TooManyFields

Raised when too many fields are packed into one bitfield

exception Frozen

Raised when a frozen bitfield is modified

module type EMPTY = sig ... end

Used for generativity on versions of OCaml older than 4.02

val max_width : int

System-dependent maximum width for a bitfield, typically 30 or 62

module type S = sig ... end
module Make (X : EMPTY) : S

Create a new bitfield type