Prefer ptrdiff_t over ssize_t · Pull Request #1448 · google/cel-cpp
`ssize_t` is a POSIX-defined type, not a C or C++ standard. `ssize_t` is not as useful of a type as it initially seems, as it only actually guarantees a range of [-1, `SSIZE_MAX`], where `SSIZE_MAX` is at least `_POSIX_SSIZE_MAX` (32767). `ptrdiff_t` is defined to be the type that results from taking the difference of two pointers. It is not guaranteed for it to be possible for all pointer differences to be represented as a `ptrdiff_t`; however, despite not theoretically having a much more stringent definition, it typically either meets or exceeds the utility of `ssize_t` on top of being a part of the C standard, thereby being usable outside of POSIX platforms. See, for example, this thread on the emacs-devel list: https://lists.gnu.org/archive/html/emacs-devel/2014-10/msg00019.html Therefore, I suggest adopting `ptrdiff_t` instead. For any of the obvious platforms, it should be exactly the same as `ssize_t` but more portable. Neither `ssize_t` nor `ptrdiff_t` are guaranteed to have a superset of the range of `size_t`, so code that uses `ssize_t` OR `ptrdiff_t` to store `size_t` values should tread carefully; this is not safe and not guaranteed to work (e.g. loops that iterate backwards should probably be adjusted.) One usage of `ssize_t` is replaced with `int64_t` instead since it is more appropriate in that circumstance.