ucx icon indicating copy to clipboard operation
ucx copied to clipboard

[WIP] UCP/API: Enforce strongly typed enums

Open gleon99 opened this issue 2 years ago • 2 comments

What

Enforce types on enums, to the extent possible by the C standard and the compilers we use.

Why ?

Prevent human errors caused by incorrect usage of enum values, therefore make our code more robust and idiot-proof.

How ?

  1. Anonymous / named enums are now types (using typedef).
  2. Use typed enums wherever possible (vars, func params). Can’t use them in struct members, would be bad practice.
  3. Add compiler flags to enforce correct usage.
  4. Fix docs accordingly.

The PR is not to be merged. Its purpose is to be a “demo” on a small part of the code of how the real change will look like – so that we can see whether it is appropriate, before proceeding to do more.

gleon99 avatar Apr 19 '22 20:04 gleon99

@yosefe @brminich WDYT? - See PR description. It looks far from perfect, but as C doesn’t really have strong enum types, I think that’s the best we can do, and it’s better than what we have now

gleon99 avatar Apr 19 '22 20:04 gleon99

This makes code better. I would start with internal changes first before changing externally exposed structures. I don't think it will break API/ABI but I think it may potentially generate warning in codes using UCX.

shamisp avatar Apr 19 '22 22:04 shamisp