Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Last active July 8, 2018 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanCarroll/121dfb870fd3da0dc52ba4e7edefe3ee to your computer and use it in GitHub Desktop.
Save EvanCarroll/121dfb870fd3da0dc52ba4e7edefe3ee to your computer and use it in GitHub Desktop.
Reword

The language specification does not prohibit any of these approaches.

  1. Permit array objects of size SIZE_MAX and make ptrdiff_t wider than size_t.

    • Pointer subtraction can not overflow and cause undefined behavior.
    • ptrdiff_t is at least one bit larger than size_t, and can accomidate any differences
    • Maximum object size is SIZE_MAX.
  2. Permit array objects of size SIZE_MAX/2 and use ptrdiff_t of the same width as size_t.

    • Pointer subtraction can not overflow and cause undefined behavior.
    • ptrdiff_t is the same size as size_t, and can accomidate any differences
    • Maximum object size is SIZE_MAX /2.
  3. Permit array objects of size SIZE_MAX and use ptrdiff_t of the same width as size_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 as size_t, and can not accomidate any differences
    • Maximum object size is SIZE_MAX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment