News for hackers. Stuff that matters.
Re:About size_t and ptrdiff_t by hamburglar on Tuesday August 18, 2015 @01:16PM (#10080547)
>> if you're just storing the delta between two pointers and then adding/subtracting this diff to get from one to the other

This would require keeping track of which one is bigger somewhere else unless you had enough room to store a sign. Seems like a pretty goofy way to go about it if you're going to the trouble of making a type specifically to hold a delta.

Re:About size_t and ptrdiff_t by phkahler on Tuesday August 18, 2015 @02:39PM (#10081229)
>> This would require keeping track of which one is bigger somewhere else unless you had enough room to store a sign.

Nope. You assume the math is being done mod 2^32 or 2^64 and it just works weather you use signed or unsigned integers. Pro-tip: the hardware does the exact same bit operations for signed and unsigned addition and subtraction (except for carry/borrow which aren't part of the C standard anyway). integer overflow is undefined, but this behavior is AFAICT universal anyway. If it didn't behave this way then a difference would in fact need the extra bit.

Re:About size_t and ptrdiff_t by hamburglar on Tuesday August 18, 2015 @08:56PM (#10083137)
Oh, excellent observation. I am wrong. :)
Re:About size_t and ptrdiff_t by aCthrowa on Tuesday August 18, 2015 @01:28PM (#10080642)
Yes, this limits the utility of ptrdiff_t. But I don't believe you're allowed to subtract arbitrary pointers in C anyway. So you might need a >63-bit char array in order to legally hit this limit, and you probably don't have 263 of RAM.

Practically, amd64 is already limited to more like 48 bits (4 levels of 9 bit pagetables describing 12 bit pages) of memory.

Re:About size_t and ptrdiff_t by 0x0 on Tuesday August 18, 2015 @02:39PM (#10081238)
I guess it could happen for applications targeting win32 with the /3GB switch