Unsigned integer data type in modern Fortran

I am wondering why there is no unsigned integer type in modern Fortran. Is there any particular reason?


Welcome to the Fortran community :raised_hands: I think there was a similar relevant discussion a few days ago on this forum and I remember reading comments that addressed your question.


There were several enlightening posts in the related discussion mentioned in the previous comment. Ultimately, you need to understand why you would want an unsigned integer type. For most people it is not to do unsigned integer arithmetic, which is counter intuitive with somewhat unexpected rules. If the goal is to have a container for bits, with the leftmost bit treated the same as the others, then what you really want is a BITS data type.


If you want BITS, you can use bitsets from stdlib: stdlib/stdlib_bitsets.md at master · fortran-lang/stdlib · GitHub

1 Like

What is really missing is unsigned integer overflow (wrap-around). It does often work in practice anyway with Fortran integers but it is not allowed and certain checks like the sanitizations in GCC will complain and halt the program.