develooper Front page | perl.perl5.porters | Postings from July 2018

RFC: Use ptrdiff_t instead of SSize_t

Thread Next
Karl Williamson
July 17, 2018 00:12
RFC: Use ptrdiff_t instead of SSize_t
Message ID:
I stumbled upon this detail in stack overflow:

"The Open Group Base Specifications Issue 7, IEEE Std 1003.1, 2013 
Edition, description of <sys/types.h> says:

The type ssize_t is capable of storing values at least in the range [-1, 

That means it doesn't necessarily work for the difference between two 
ptrs, which is something I have used it for.

But ptrdiff_t must be capable of storing any such difference.  Also, any 
object's size can be expressed as the difference between its ending and 
starting pointers, so ptrdiff_t must be able to store anything ssize_t, 
STRLEN or plain size_t can store, as well.

I think we should just redefine our SSize_t to be ptrdiff_t, and be done 
with it.  ptrdiff_t is C89 whereas ssize_t is POSIX, which I consider to 
be an additional advantage to using ptrdiff_t.  There doesn't need to be 
a Configure probe for ptrdiff_t.  We can rip out the logic for figuring 
out SSize_t and ptrdiff_t.

There is this comment and accompanying code in perl.h, by Brian Fraser:
  /* ptrdiff_t is C11, so undef it under pedantic builds */

which seems wrong to me.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About