Many external declarations in the OCaml standard library have a % at the beginning of the function name, such as the definition of int_of_float:
external int_of_float : float -> int = "%intoffloat"
What does the '%' mean?
Many external declarations in the OCaml standard library have a % at the beginning of the function name, such as the definition of int_of_float:
external int_of_float : float -> int = "%intoffloat"
What does the '%' mean?
external with % are special external, that will be handled specially by the compiler. For example, with int_of_float, ocamlc will compile it into a call of some C function, but with ocamlopt, it will compile it into some special assembler opcode that transform double to integer.
There's a lot of %foo special primitives hiding in the compiler. I think the best list is available in bytecomp/translcore.ml, in the ocaml compiler sources. Let's see how many I can list here:
These comparisons have specialized versions for int, float, string, nativeint, int32 and int64, and will auto-specialize if the types are known at compile-time.
%identity, %ignore, %field0, %field1, %setfield0, %makeblock, %makemutable, %raise, %incr, %decr, %seqand, %seqor, %boolnot%negint, %succint, %predint, %addint, %subint, %mulint, %divint, %modint, %andint, %orint, %xorint, %lslint, %lsrint, %asrint%eq, %noteq, %ltint, %leint, %gtint, %geint%intoffloat, %floatofint, %negfloat, %absfloat, %addfloat, %subfloat, %mulfloat, %divfloat%eqfloat, %noteqfloat, %ltfloat, %lefloat, %gtfloat, %gefloat%string_length, %string_safe_get, %string_safe_set, %string_unsafe_get, %string_unsafe_set%array_length, %array_safe_get, %array_safe_set, %array_unsafe_get, %array_unsafe_set%obj_size, %obj_field, %obj_set_field, %obj_is_int%lazy_force%{nativeint,int32,int64}: _of_int, _to_int, _neg, _add, _sub, _mul, _div, _mod, _and, _or, _xor, _lsl, _lsr, _asr%nativeint_{of,to}_int32, int64_{of,to}_int32, int64_{of,to}_nativeint%caml_ba_ref_{1,2,3}, %caml_ba_set_{1,2,3}, %caml_ba_unsafe_ref_{1,2,3}, %caml_ba_unsafe_set_{1,2,3}%send, %sendself, %sendcacheThat's all I can find.