Using signed numerics as the underlying type for a bits
declaration is prohibited:
{% include “docs/reference/fidl/language/error-catalog/label/_bad.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0069.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
Instead, use any one of the following: uint8
, uint16
, uint32
, or uint64
:
{% include “docs/reference/fidl/language/error-catalog/label/_good.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0069.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
Unlike enum
declarations, which allow both signed and unsigned integers (see: fi-0070), bits
declarations only permit the latter. This is because each bits
member necessarily represents a specific underlying bit in a bit array (this is the reason that fi-0067 exists). This is most cleanly represented as a single unsigned integer. The binary representation of unsigned integer maps directly to a single bit (2 to the power of its index), whereas the negative numbers in signed integers almost always select multiple bits due to the mechanics of the two's complement representation.
Note: if the value given for the underlying type of a bits
is not an identifier for a type, it will result in fi-0013: Invalid wrapped type instead.