set icon indicating copy to clipboard operation
set copied to clipboard

Use of "int" return type is problematic

Open ericpruitt opened this issue 4 months ago • 0 comments

For *NIX systems, "int" is only guaranteed to be 16 bits wide. It's typically 32 bits, but I think that still poses a practical problem.

If "int" is equivalent to "int32_t", the max fullness ratio means we can only have up to ~500M elements before we have to worry about the positive range of "int" being too small to support all values. 500M is a large number but not infeasible to reach. I think you could make the limits practically infinite by using uint64_t for the return types then having the result values count down from the maximum value of the type like:

typedef uint64_t enum {
    SET_TRUE = UINT64_MAX - 1,
    SET_FALSE = UINT64_MAX - 2,
    SET_MALLOC_ERROR = UINT64_MAX - 3,
    SET_CIRCULAR_ERROR = UINT64_MAX - 4,
    SET_OCCUPIED_ERROR = UINT64_MAX - 5,
    SET_ALREADY_PRESENT = UINT64_MAX - 6,
} set_result;

Then the return types could be adjust to make them uint64_t. Let me know what you think, and if that sounds like a good idea to you, I can make the PR for the change.

ericpruitt avatar Dec 06 '25 17:12 ericpruitt