I need a pair of standard integer types, signed and unsigned, that correspond to (a reasonable interpretation of) the machine word size, and that are guaranteed to be the same size as each other.
On platforms with a clean address model, intptr_t
and uintptr_t
fit the bill, so using those is certainly a possibility.
However, there is a possibility that the code in question may need to run on various embedded systems. I'm guessing some of these still use CPUs with a 286-style architecture where the largest efficient integer type is smaller than a pointer - please correct me if this is not so - but if it is, then there is a case to be made for using the smaller integer type.
That smaller integer type would presumably correspond to size_t
and ptrdiff_t
- but are those types guaranteed to be the same size as each other? I do need to be able to convert back and forth between the signed and unsigned type without loss.
Is there something else I should be considering?
I've decided zmccord is right, intptr_t
and uintptr_t
are the types that are both guaranteed to be available, and clearly and unambiguously sufficient. If a particular variable needs to be smaller than that for a particular platform, it can be declared with the specific size it needs.