xdrpp / xdrpp

Home Page:http://xdrpp.github.io/xdrpp/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In enums negative integer used as error value but can be valid

bartekn opened this issue · comments

Here's an example of generated code for enum:

  static Constexpr int _xdr_field_number(_xdr_case_type which) {
    return which == KEY_TYPE_ED25519 ? 1
      : -1;
  }

However, according to XDR spec enums have the same representation as signed integers. That means that they can have a negative values.

The _xdr_field_number is just an integer designating which case clause is currently selected. It is used to decide if a particular union field needs to be constructed or destructed in places like the assignment operator. It has no bearing on the actual value of the union tag, but just the order in which that case appeared. 0 is reserved for default, and -1 means error.

In short, there should be no problem using signed enums with value -1.