Erlang Mailing Lists

Author Message

<  Erlang  ~  Splitting binary stuff

wolfgke
Posted: Sat Nov 10, 2007 9:35 am Reply with quote
User Joined: 16 Sep 2007 Posts: 16
Dear people,
the following code did not work:

Code:

<<_:(CurrentSize-32), T:32, _/binary>> = ActExpandedKey,
% ...


The compiler complains with "illegal bit size" in this line.

So I played around: this code seems to work as it has to:

Code:

Foo=(CurrentSize-32),             
<<_:Foo, T:32, _/binary>> = ActExpandedKey,
% ...


But I don't know the reason why it is like that. Sad

Could anybody help me, please?
View user's profile Send private message
Kenneth
Posted: Sun Nov 11, 2007 8:59 pm Reply with quote
Joined: 28 Feb 2005 Posts: 5 Location: Stockholm, Sweden
[quote="wolfgke"]Dear people,
the following code did not work:

Code:

<<_:(CurrentSize-32), T:32, _/binary>> = ActExpandedKey,
% ...


The compiler complains with "illegal bit size" in this line.

It is a documented limitation of the bit-syntax that the size must be an integer literal or a variable bound to an integer value.

In your second example you use a variable bound to
an integer value which is ok.

See
http://www.erlang.org/doc/reference_manual/expressions.html#6.16

/Kenneth (Erlang/OTP team at Ericsson)
View user's profile Send private message
wolfgke
Posted: Tue Nov 20, 2007 1:08 pm Reply with quote
User Joined: 16 Sep 2007 Posts: 16
A belated Thank-you for your explanation. Very Happy
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum