[erlang-questions] Unexpected list_to_binary behavior

Steve Vinoski vinoski@REDACTED
Tue Mar 18 14:19:40 CET 2014


On Tue, Mar 18, 2014 at 9:13 AM, Valentin Micic <valentin@REDACTED>wrote:

> Hi all,
>
> (my apologies if this has been covered already)
>
> Is there any reason why:
>
> *(twist@REDACTED)820> list_to_binary( lists:seq(1,255) ).*
> *<<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,*
> *  22,23,24,25,26,27,28,29,...>>*
>
> works, but
>
> (twist@REDACTED)821> list_to_binary( lists:seq(1,256) ).
> ** exception error: bad argument
>      in function  list_to_binary/1
>         called as
> list_to_binary([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
>                                   23,24,25,26,27,28|...])
>
> breaks on *Erlang 16B02*? Was the limit to 255 characters for
> list_to_binary/1 always there and I just failed to see it before?
>

This has nothing to do with the number of characters, but rather that you
can't represent the value 256 in a byte:

1> list_to_binary([256]).
** exception error: bad argument
     in function  list_to_binary/1
        called as list_to_binary([256])

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140318/04b698b2/attachment.htm>


More information about the erlang-questions mailing list