← Back to context

Comment by adrian_b

20 hours ago

You are perfectly right, but neither C nor C++ nor many more recent languages derived from them have non-negative integers.

The so-called "unsigned" integers of C are integer residues, where each value can be interpreted either as both positive and negative or as neither positive nor negative. In any case no "unsigned" value can be said to be non-negative.

You have to go back to languages not contaminated by C, like Ada, to find true non-negative integers among the primitive data types.

In C++, it is possible to define a non-negative integer type, which can have good performance if you implement its operations in assembly language.

However I am not aware of an open-source library including such a type.

I really appreciate your comments in this thread adrian_b. Could you point me at a brief summary of how Ada (or Pascal?) non-negative ints work? What is a compile error, what is a guaranteed run-time error, etc.