<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-01-26 21:20 GMT+01:00 Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr">+1<div><br></div><div>with C i was always wondering, why C standard does not provides </div><div>an unsigned integer type which size strictly corresponds to size of pointer type, e.g.</div><div>sizeof(some standard uint) == sizeof(void*)</div><div>that would solve so many problems and make thing so much easier..</div><div><br></div></div></blockquote><div><br></div><div>In C99, there is intptr_t (and all the accompanying MACROS for printf/scanf formats, maximum value etc...)<br><br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>instead they had this:</div><div><a href="http://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html" target="_blank">http://www.gnu.org/software/<wbr>libc/manual/html_node/<wbr>Important-Data-Types.html</a><br></div><div><dl style="color:rgb(0,0,0);font-family:"times new roman";font-size:medium"><dt>Data Type: <b>ptrdiff_t</b></dt><dd><p>This is the signed integer type of the result of subtracting two pointers. For example, with the declaration <code>char *p1, *p2;</code>, the expression <code>p2 - p1</code> is of type <code>ptrdiff_t</code>. This will probably be one of the standard signed integer types (<code>short int</code>, <code>int</code> or <code>long int</code>), but might be a nonstandard type that exists only for this purpose.</p></dd></dl><dl style="color:rgb(0,0,0);font-family:"times new roman";font-size:medium"></dl></div><div><br></div><div>it is easy to see, that sizeof(ptrdiff_t) should be _at least_ the sizeof(void*), else it won't be able to cover all possible values when taking difference between two pointers..</div><div>alas, it is signed.. and alas, nothing says that it cannot be _more_ than size of pointer in memory.. simply because you can always fit values that take 32 bits into 64-bit value holder.. </div></div></blockquote><div><br></div><div>Technically you should only compare pointers that points to parts of a same structure or array (or byte just after the end of an array), otherwise it's UB.<br></div><div>I guess this should apply to ptrdiff_t, in which case ptrdiff_t should be as long as a size_t, except it is signed.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>One could say, that there's size_t that could be used as a unsigned alternative to ptrdiff_t,</div><div>unfortunately, ISO gives no guarantees that its size corresponds to pointer size.</div><div><br></div></div></blockquote><div><br></div><div>size_t does not necessarily fit intptr_t indeed, use the right type.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div><br>Btw,look what i found :)<br><a href="https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html#Integer-Overflow-Builtins" target="_blank">https://gcc.gnu.org/<wbr>onlinedocs/gcc/Integer-<wbr>Overflow-Builtins.html#<wbr>Integer-Overflow-Builtins</a><br></div><div><br></div><div>that could be useful for implementing small-int arithmetics in plain C.. unfortunately this is extension, and don't shoot for  proposing to use non-standard C herecy :)</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 26 January 2017 at 21:37, John McIntosh <span dir="ltr"><<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.<wbr>com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br>+1<br>
<br>
Sent from my iPhone<br>
<br>
> On Jan 26, 2017, at 10:58, David T. Lewis <<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>> wrote:<br>
><br>
><br>
> +1<br>
><br>
> Dave<br>
><br>
>><br>
>> Surely since we’re concerned about (ab)use of signed values for pointers<br>
>> to words we ought to define a â€˜proper’ sqOop thing and use that<br>
>> instead of a slightly cleaned up derivative of how the Slang default was<br>
>> left as â€˜int’ twenty years ago?<br>
>><br>
>> Yes, any change means a bunch of work to do but isn’t that always the<br>
>> price to improve things?<br>
>><br>
>> tim<br>
>> --<br>
>> tim Rowledge; <a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" rel="noreferrer" target="_blank">http://www.rowledge.org/tim</a><br>
>> Strange OpCodes: LB: connect Line-voltage to BITNET<br>
>><br>
>><br>
>><br>
><br>
><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-2800274000484159545gmail_signature" data-smartmail="gmail_signature">Best regards,<br>Igor Stasenko.</div>
</div>
<br></blockquote></div><br></div></div>