<div class="gmail_quote">On 20 February 2012 20:07, Artur Skawina <span dir="ltr"><<a href="mailto:art.08.09@gmail.com">art.08.09@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 02/20/12 13:32, Stewart Gordon wrote:<br>
> On 20/02/2012 03:44, Artur Skawina wrote:<br>
> <snip><br>
>>> Why would you want to do that, as opposed to use one of the pointer types (which is<br>
>>> indeed required for GC to work correctly)?<br>
>><br>
>> That's how it can be used in *C*.<br>
>><br>
>> And the reason it needs to be exposed to D code is for interoperability with C.<br>
><br>
> IINM, C calling conventions care only about the size of a type, not the name or intrinsic nature of it. Therefore this is a non-issue.<br>
<br>
</div></div>struct S { uintptr_t a; };<br>
extern (C) uintptr_t f(S* s, uintptr_t* blah);<br>
<br>
"uintptr_t" is not the best example here (because it will rarely appear in C<br>
APIs), but still shows the problem - you need to know what it is - otherwise<br>
you're left with guessing and eg assuming that uintptr==size_t.<br>
<br>
Fixing historical mistakes can be hard.<br>
<br>
There are basically three types of integer types:<br>
<br>
a) known fixed size types, such as a 32-bit wide unsigned int<br>
b) types, that are not explicitly sized, but meet certain criteria,<br>
eg: sizeof(short)<=sizeof(int)<=sizeof(long)<br>
c) externally defined types, which must always have the same representation,<br>
the above uintptr_t example falls into this category.<br>
<br>
'C' didn't have the (a) types, so everybody had to redefine u8/s16/u32/s64 etc.<br>
'D' added these as builtin types so that problem was solved. Unfortunately,<br>
instead of eg using the de facto std s16/s32/s64, D reused short/int/long.<br>
'C's short/int/long were poorly (too loosely) defined, but what should have<br>
been done is defining them in 'D' as, for example:<br>
<br>
int: efficient integer type, fitting in a CPU register and at least 32 bit wide;<br></blockquote><div><br></div><div>No, this would be very very bad. People would use 'int' out of habit in data structures, and mess up binary compatibility and alignment rules.</div>
<div>I personally quite like D's int types as they are, but note there are some 'missing' (well, not missing, as we're discussing, but they are not well defined, or named, and needlessly aliased)</div><div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
long: efficient integer type, fitting in a CPU register and as wide as a GPR.<br></blockquote><div><br></div><div>I don't think the term 'long' here, as opposed to 'int' draws this distinction... so I really can't buy into this logic.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Fixing things up now, with for example "nativeInt" (maps to "int" above) and<br>
"widestInt" (the "long" above), is not easy. They are needed, that's why<br>
threads like this one appear, but simply adding them to the language or std<br>
library [1] wouldn't be enough. Why? Think literals, promotion and auto --<br>
I'm afraid programmers working with 'native' ints may not be expecting<br>
expressions evaluating to a narrower type.<br>
<br>
So there probably is no ideal simple solution for D2. For 64-bit platforms and<br>
a future D3 language, the int/long, as defined above, would be a mostly backward<br>
compatible change.<br></blockquote><div><br></div><div>I prefer to explicitly identify these types personally. Predictable sized types are better to have people punching away with no real consideration to the specific use case.</div>
<div>People should only use these resizing types deliberately when they know what they're doing.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">artur<br>
<br>
[1] fundamental types like these should not require any imports, so object.d<br>
and/or compiler is the best place for them.<br>
</blockquote></div><br>