4

The C Standard defines intptr_t and uintptr_t in <stdint.h> this way:

7.20.1.4 Integer types capable of holding object pointers

The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

intptr_t

The following type designates an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer:

uintptr_t

These types are optional.

Why are these types optional?
Are there any examples of architectures where these types cannot be defined?

chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • I don't want to bother and your question is more illustrative but what about this [question](https://stackoverflow.com/q/53380203/12139179)? Do you want to ask explicit with C (not C/C++ mishmash) and C standard focus or does this answer your question? – RobertS supports Monica Cellio Sep 05 '20 at 22:27
  • I seem to recall there exist microcontrollers with 8-bit general-purpose registers, and 16-bit special-purpose registers for memory access. – Igor Tandetnik Sep 05 '20 at 22:28
  • 1
    C committee has a long lasting problem with existing ABIs and some integer types for example `intmax_t`. To avoid similar problems but to be flexible at the same time they decided to make some types which may cause similar ABI problems optional. – 0___________ Sep 05 '20 at 22:32
  • @RobertSsupportsMonicaCellio: Indeed the question in reference does answer mine. SO's duplicate finder in the Ask Question page is ineffective. I also do not understand why the other question is tagged c++. – chqrlie Sep 05 '20 at 22:41
  • @chqrlie Experienced the same. Since a while, I always use Google to look for questions on SO. – RobertS supports Monica Cellio Sep 05 '20 at 22:45
  • 1
    @chqrlie In ISO C++ they are optional, too. - Ref.: C++17, 21.4.1 – RobertS supports Monica Cellio Sep 05 '20 at 22:49
  • @IgorTandetnik: Well, `int` is required to be at least 16 bits, so such a machine has to be able to support 16-bit integers anyway, at which point it might as well `typedef int intptr_t;`. – Nate Eldredge Sep 06 '20 at 01:20

0 Answers0