zero length segments!
Tue Sep 24 16:40:53 CEST 2002
The bitsize can not be an arbitrary expression, just bind the size before
t(Bit) when integer(Bit) ->
S = (31 - Bit),
<<_:S, Flag:1, _:(Bit)>> = <<1:32>>,
----- Original Message -----
From: "Vance Shipley" <>
Sent: Tuesday, September 24, 2002 4:02 PM
Subject: Re: zero length segments!
> Well didn't I speak too soon! While this works wonderfully in the shell
> it won't complile. :(
> Eshell V5.1.2 (abort with ^G)
> 1> T = fun(Bit) -> <<_:(31 - Bit), Flag:1, _:(Bit)>> = <<1:32>>, Flag end.
> 2> T(0).
> 3> T(1).
> t(Bit) when integer(Bit) ->
> <<_:(31 - Bit), Flag:1, _:(Bit)>> = <<1:32>>,
> 1> c(t).
> ./t.erl:5: illegal bit size
> The problem seems to be with the expression (31 - Bit).
> Any idea how to get past this?
> Vance Shipley
> Motivity Telecom Inc.
> +1 519 579 5816
> On Tue, Sep 24, 2002 at 06:33:23AM -0400, Vance Shipley wrote:
> > Was I ever happily suprised when I found that this was a valid
> > <<0:8, 1:24, 0:0>>
> > It results in:
> > <<0,0,0,1>>
> > The reason this is so good is that it I don't have to handle a special
> > case when X=0:
> > Flag = <<_:(31-X), Flag:1, _:(X)>>
> > Of course I'm sure that that is why it works, I'm just very happy about
> > -Vance
More information about the erlang-questions