[erlang-questions] Bit-level binaries broken in R11B-5?

Bjorn Gustavsson <>
Sun Sep 16 07:09:22 CEST 2007


"Bob Ippolito" <> writes:

> I was playing around with bit-level binaries in R11B-5 to see if we
> could use them to make some of our code shorter and faster, however it
> seems that some of the operations that we'd want to do give very
> unexpected results. Here's a short test module that uses two different
> methods of concatenating N bit long binaries and ends up with mostly
> the incorrect results.

Yes, the result is wrong. The correct result (which you will get in
R12B) is a 'badarg' exception.

To make your program work, you must change the following lines

   R1 = <<A/binary, B/binary>>,
   R2 = <<<<N/binary>> || N <- [A, B]>>,

to

   R1 = <<A/bitstr, B/bitstr>>,
   R2 = <<<<N/bitstr>> || N <- [A, B]>>,

Note that bit-level binaries and binary comprehensions are EXPERIMENTAL
and UNSUPPORTED features in R11B.

In the final R12B, there will probably be changes to the
bit-level binaries. Source code that use bit-level binaries with
the R11B syntax will compile in R12B-0, but not in R12B-1.
(The only reason for allowing the experimental syntax in R12B-0 is that
we bootstrap the next release using the latest official release.)

The performance of most bit syntax code will be better in R12B than
in R11B (it should never be slower).

If you want to know what the bit-level binary syntax probably will look like
in R12B, see

http://www.erlang.org/pipermail/eeps/2007-September/000005.html
http://www.erlang.org/eeps/eep-0004.html
http://www.erlang.org/eeps/eep-0006.html

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list