Re:A Better Way to Implement Bit Fields
by masklinn on Thursday November 15, 2018 @05:09AM
(#18458162)
Erlang's bit syntax is indeed brilliant, but it's a bit different from C's bit fields: bit fields are both mapping and storage, Erlang's bit syntax is only mapping (parsing and serialisation) e.g. your bit-wide flag is going to expand to a full integer (erlang so infinite precision & heap allocated) at runtime, which may or may not be desirable.
Furthermore IIRC an Erlang pattern can be either matching or creation, you can't "abstract" a pattern to do both, so if you need to both parse and generate your binary thing will need to be written twice (at least).
This may or may not be an issue, but at the end of the day it's not quite equivalent to C's bitfields. It's very convenient though.
Furthermore IIRC an Erlang pattern can be either matching or creation, you can't "abstract" a pattern to do both, so if you need to both parse and generate your binary thing will need to be written twice (at least).
This may or may not be an issue, but at the end of the day it's not quite equivalent to C's bitfields. It's very convenient though.