The language specification does not prohibit any of these approaches.
-
Permit array objects of size
SIZE_MAX
and makeptrdiff_t
wider thansize_t
.- Pointer subtraction can not overflow and cause undefined behavior.
ptrdiff_t
is at least one bit larger thansize_t
, and can accomidate any differences- Maximum object size is
SIZE_MAX
.
-
Permit array objects of size
SIZE_MAX
/2
and useptrdiff_t
of the same width assize_t
.- Pointer subtraction can not overflow and cause undefined behavior.
ptrdiff_t
is the same size assize_t
, and can accomidate any differences- Maximum object size is
SIZE_MAX /2
.
-
Permit array objects of size
SIZE_MAX
and useptrdiff_t
of the same width assize_t
- Pointer subtraction can overflow and cause undefined behavior. Overflow occurs if the pointers are farther than
SIZE_MAX / 2
elements apart. ptrdiff_t
is the same size assize_t
, and can not accomidate any differences- Maximum object size is
SIZE_MAX
- Pointer subtraction can overflow and cause undefined behavior. Overflow occurs if the pointers are farther than