www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - size_t + ptrdiff_t

reply Manu <turkeyman gmail.com> writes:
--002354530350546df104b9526bce
Content-Type: text/plain; charset=UTF-8

Okay, so it came up a couple of times, but the questions is, what are we
going to do about it?

size_t and ptrdiff_t are incomplete, and represent non-complimentary
signed/unsigned halves of the requirement.
There are TWO types needed, register size, and pointer size. Currently,
these are assumed to be the same, which is a false assumption.

I propose size_t + ssize_t should both exist, and represent the native
integer size. Also something like ptr_t, and ptrdiff_t should also exist,
and represent the size of the pointer.

Personally, I don't like the _t notation at all. It doesn't fit the rest of
the D types, but it's established, so I don't expect it can change. But we
do need the 2 missing types.

There is also the problem that there is lots of code written using the
incorrect types. Some time needs to be taken to correct phobos too I guess.

--002354530350546df104b9526bce
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Okay, so it came up a couple of times, but the questions is, what are we go=
ing to do about it?<div><br></div><div>size_t and ptrdiff_t are incomplete,=
 and represent non-complimentary signed/unsigned halves of the requirement.=
</div>
<div>There are TWO types needed, register size, and pointer size. Currently=
, these are assumed to be the same, which is a false assumption.</div><div>=
<br></div><div>I propose size_t + ssize_t should both exist, and represent =
the native integer size. Also something like ptr_t, and ptrdiff_t should al=
so exist, and represent the size of the pointer.</div>
<div><br></div><div>Personally, I don&#39;t like the _t notation at all. It=
 doesn&#39;t fit the rest of the D types, but it&#39;s established, so I do=
n&#39;t expect it can change. But we do need the 2 missing types.</div>
<div><br></div><div>There is also the problem that there is lots of code wr=
itten using the incorrect types. Some time needs to be taken to correct pho=
bos too I guess.</div>

--002354530350546df104b9526bce--
Feb 19 2012
next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 14:59, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are we going
to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
signed/unsigned
 halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently, these
are assumed
 to be the same, which is a false assumption.

The whole point of size_t and ptrdiff_t is that they are integer types that span the address space. So that the size of an allocated block of memory (and consequently, the number of elements in an array) is bound to fit in a size_t, and the displacement between two memory locations is bound to fit in a ptrdiff_t. What would this "register size" type you are proposing be for, exactly? <snip>
 There is also the problem that there is lots of code written using the
incorrect types.

Like what?
Feb 19 2012
next sibling parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 19-02-2012 16:26, Manu wrote:
 On 19 February 2012 17:09, Stewart Gordon <smjg_1998 yahoo.com
 <mailto:smjg_1998 yahoo.com>> wrote:

     On 19/02/2012 14:59, Manu wrote:

         Okay, so it came up a couple of times, but the questions is,
         what are we going to do about it?

         size_t and ptrdiff_t are incomplete, and represent
         non-complimentary signed/unsigned
         halves of the requirement.
         There are TWO types needed, register size, and pointer size.
         Currently, these are assumed
         to be the same, which is a false assumption.


     The whole point of size_t and ptrdiff_t is that they are integer
     types that span the address space.  So that the size of an allocated
     block of memory (and consequently, the number of elements in an
     array) is bound to fit in a size_t, and the displacement between two
     memory locations is bound to fit in a ptrdiff_t.

     What would this "register size" type you are proposing be for, exactly?


 You also need a type that knows the native word size of the machine, not
 just a pointer width. If size_t should be the pointer size, then there
 needs to be some other type that specifies the register width of the
 architecture.

     <snip>

         There is also the problem that there is lots of code written
         using the incorrect types.

     <snip>

     Like what?


 There is code that assumes size_t is the width of the pointer, and other
 code that assumes size_t is the width of the native int. Only one of
 those is correct, whichever you declare it to be, and another type needs
 to be invented to define the other.
 It is common that pointers are the same width as the int regs, but there
 are many architectures where it's not true.

Also, fun fact: Even on x86, pointers aren't necessarily 32- or 64-bit wide - in kernel space. :) -- - Alex
Feb 19 2012
prev sibling next sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"Vladimir Panteleev" <vladimir thecybershadow.net> wrote in message 
news:valucopzdhxdjymkgvuq forum.dlang.org...
 On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:
 There is code that assumes size_t is the width of the pointer

When is this not true? I can only think of 16-bit far pointers.

8-bit embedded quite often has 16-bit pointers.
Feb 19 2012
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 16:07, Daniel Murphy wrote:
 "Vladimir Panteleev"<vladimir thecybershadow.net>  wrote in message
 news:valucopzdhxdjymkgvuq forum.dlang.org...
 On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:
 There is code that assumes size_t is the width of the pointer

When is this not true? I can only think of 16-bit far pointers.

8-bit embedded quite often has 16-bit pointers.

And has an 8-bit size_t? Just found the bit I read before and was trying to find again http://www.dlang.org/portability.html "Use size_t as an alias for an unsigned integral type that can span the address space. Array indices should be of type size_t." Of course, anything below 32-bit is irrelevant to D, but according to cplusplus.com size_t is defined to be the type returned by sizeof. But where it explains sizeof it doesn't state what type that is, and I don't know what the C or C++ standard says about it. Stewart.
Feb 19 2012
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 15:26, Manu wrote:
<snip>
 There is code that assumes size_t is the width of the pointer, and other code
that assumes
 size_t is the width of the native int.

How does it do that? Indeed, how does code rely on the concept of native int at all? Stewart.
Feb 19 2012
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 17:04, Manu wrote:
<snip>
     Indeed, how does code rely on the concept of native int at all?

 You can't imagine any situation where you might want to know how big an int is?

Hang on ... are we talking here about some "native int", or the int type? If you want to know the size of a "native int", I think you would need to know more about how the particular machine works internally in order to take advantage of it. If you want to know the size of an int, you would just use int.sizeof. Problem solved. Stewart.
Feb 19 2012
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 17:51, Manu wrote:
<snip>
     Hang on ... are we talking here about some "native int", or the int type?

 I don't really understand your resistance? I'm going to have the type when I
need it, the
 question is, will it be standardised, or will I (& everyone else) invent the
name and
 introduce a block of (probably not very portable) version() bullshit at the
top of their
 module?

I'm not saying we shouldn't have native integer types in D. Maybe what's needed is to be clearer on what's meant exactly by a native integer type. And then add the types to Phobos/druntime. I particularly don't understand your suggestion of the names "size_t" and "ssize_t" for these types. They don't seem to me to denote the size of anything. I guess "nativeInt" and "nativeUint", defined in whatever module would be suitable, would be one possibility. Maybe someone has a better idea. But knowing what code in Phobos/druntime should be using native integer types might help put the problem in better perspective. Stewart.
Feb 19 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/19/2012 3:15 PM, Manu wrote:
 Ultimately I don't care, I suspect the prior commitment to size_t and ptrdiff_t
 can not be changed (although redefining their meaning would not be a breaking
 change, it just might show some cases of inappropriate usages)
 I agree that nativeInt should probably be in the standard library, but I'm
 really not into that name. It's really long and ugly. That said, I basically
 hate size_t too, it doesn't seem very D-ish, reeks of C mischief... and C
stuffs
 up those types so much. It's not dependable what they actually mean in C (ie.
 ptr size/native word size) on all compilers I've come in contact with :/

I really think that simply adding c_int and c_uint to core.stdc.config will solve the issue. After all, is there any case where the corresponding C int type would be different from a nativeInt?
Feb 19 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/20/2012 3:02 AM, Manu wrote:
 ? I must have misunderstood something... I've never seen a 64bit C compiler
 where 'int' is 64bits.

What are you using in C code for a most efficient integer type?
Feb 20 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/20/2012 3:28 AM, Manu wrote:
 Even size_t is often
 broken in C. I have worked on 64bit systems with 32bit pointers where size_t
was
 still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe my
 memory fails me)

I don't know how that could be considered C standard compliant.
 I want to be confident when I declare a numeric type that can interact with
 pointers, and also when I want the native type.

I think you're probably best off for now by doing your own alias for it.
Feb 20 2012
next sibling parent reply Artur Skawina <art.08.09 gmail.com> writes:
On 02/21/12 04:12, James Miller wrote:
 If the only problem is that we need some more types, can't we add them
 in? I don't see the problem with having verbose, import-only names for
 things outside the norm, alias them if you want, longer names are
 better for newcomers. For example, what is ptrdiff_t? I have never
 seen that before, and the name doesn't help me, from the alias in
 druntime, it seems to be the type that represents the difference
 between 2 pointers. Help me out here, what on earth would I use that
 for?

In C, for storing the result of (a-b), where a and b are pointers.
 (On a side note to that, no way is ssize_t a good name, ever, forwards
 and backwards, what on earth is it? super-size_t? here to save you?
 shady-size_t? you have to make sure it doesn't sell you drugs?
 size-size_t? it has a stammer?)

It's signed, unlike the unsigned 'size_t'. Types like ptrdiff_t are not necessary in D, because you can write portable code using 'auto' and 'typeof()' - std C didn't have these, so a type had to be invented for everything. D only lacks the 'native' types; while you can, in most cases, find them out using import and version(), the compiler obviously already knows what they are for every supported target. So it's just about exposing them to the compiled code in a std, defined way. The 'C' types are only needed for interoperability, for example - the glib bindings needed these:
 import core.stdc.limits: c_long, c_ulong;
 alias  int c_int;  // Assumes 32-bit wide int.
 alias uint c_uint; // Assumes 32-bit wide int.
 import core.sys.posix.sys.types : time_t, ssize_t;

IIRC I did not find the C int types conveniently defined anywhere and didn't want to use GCC extensions. ssize_t is std and common enough that it could live outside that sys.posix module. Maybe this is also true for time_t and a few others that weren't needed in this case. artur
Feb 21 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 1:03 AM, Artur Skawina wrote:
 Types like ptrdiff_t are not necessary in D, because you can write portable
 code using 'auto' and 'typeof()' - std C didn't have these, so a type had
 to be invented for everything.

And, in fact, object.di contains: alias typeof(int.sizeof) size_t; alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
Feb 21 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 12:33 AM, Manu wrote:
 On 21 February 2012 01:22, Walter Bright <newshound2 digitalmars.com
 <mailto:newshound2 digitalmars.com>> wrote:

     On 2/20/2012 3:28 AM, Manu wrote:

         Even size_t is often
         broken in C. I have worked on 64bit systems with 32bit pointers where
         size_t was
         still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but
maybe my
         memory fails me)


     I don't know how that could be considered C standard compliant.


 I don't know about you, but I very rarely get to work with a C compiler that is
 'standards compliant'.. that concept is kinda like a cruel joke in my
 experience. Does one even exist? :)

The C99 Standard sez: "The types are ptrdiff_t which is the signed integer type of the result of subtracting two pointers; size_t which is the unsigned integer type of the result of the sizeof operator;" I don't know of any excuse for getting this wrong.
Feb 21 2012
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 22/02/2012 02:23, Walter Bright wrote:
<snip>
 The C99 Standard sez:

 "The types are ptrdiff_t which is the signed integer type of the result of
subtracting two
 pointers; size_t which is the unsigned integer type of the result of the
sizeof operator;"

And what does it say about what type the sizeof operator returns? Stewart.
Feb 22 2012
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-02-20 12:02, Manu wrote:
 On 20 February 2012 02:48, Walter Bright <newshound2 digitalmars.com
 <mailto:newshound2 digitalmars.com>> wrote:

     On 2/19/2012 3:15 PM, Manu wrote:

         Ultimately I don't care, I suspect the prior commitment to
         size_t and ptrdiff_t
         can not be changed (although redefining their meaning would not
         be a breaking
         change, it just might show some cases of inappropriate usages)
         I agree that nativeInt should probably be in the standard
         library, but I'm
         really not into that name. It's really long and ugly. That said,
         I basically
         hate size_t too, it doesn't seem very D-ish, reeks of C
         mischief... and C stuffs
         up those types so much. It's not dependable what they actually
         mean in C (ie.
         ptr size/native word size) on all compilers I've come in contact
         with :/


     I really think that simply adding c_int and c_uint to
     core.stdc.config will solve the issue. After all, is there any case
     where the corresponding C int type would be different from a nativeInt?


 ? I must have misunderstood something... I've never seen a 64bit C
 compiler where 'int' is 64bits.

According to Wikipedia, two out of four 64-bit data models uses 64bit integers, ILP64 and SILP64: http://en.wikipedia.org/wiki/64-bit#64-bit_data_models -- /Jacob Carlborg
Feb 20 2012
prev sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Feb 20, 2012, at 3:16 AM, Walter Bright wrote:

 On 2/20/2012 3:02 AM, Manu wrote:
 ? I must have misunderstood something... I've never seen a 64bit C =


 where 'int' is 64bits.

What are you using in C code for a most efficient integer type?

I can't answer for Manu, but I imagine one should probably use = int_fast32_t, etc.=
Feb 20 2012
prev sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 02/20/12 01:48, Walter Bright wrote:
 On 2/19/2012 3:15 PM, Manu wrote:
 Ultimately I don't care, I suspect the prior commitment to size_t and ptrdiff_t
 can not be changed (although redefining their meaning would not be a breaking
 change, it just might show some cases of inappropriate usages)
 I agree that nativeInt should probably be in the standard library, but I'm
 really not into that name. It's really long and ugly. That said, I basically
 hate size_t too, it doesn't seem very D-ish, reeks of C mischief... and C
stuffs
 up those types so much. It's not dependable what they actually mean in C (ie.
 ptr size/native word size) on all compilers I've come in contact with :/

I really think that simply adding c_int and c_uint to core.stdc.config will solve the issue. After all, is there any case where the corresponding C int type would be different from a nativeInt?

64bit platforms, depending on the definition of nativeInt. I'm not sure what it should map to, but 'widestInt' seems to be the result asked for in this thread. But would that really be different from c_long? artur
Feb 19 2012
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/19/2012 8:23 AM, Manu wrote:
 On 19 February 2012 18:03, Vladimir Panteleev <vladimir thecybershadow.net
 <mailto:vladimir thecybershadow.net>> wrote:

     On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:

         There is code that assumes size_t is the width of the pointer


     When is this not true? I can only think of 16-bit far pointers.


 Ignoring small embedded systems (for which it is almost always true), some that
 immediately come to mind:

   NaCl (Google Native Client) - x64 arch, 32bit pointers ... <- of immediate
 concern to me
   PPC based consoles; PS3, X360, Wii, WiiU (not released yet) - 64bit, all
32bit
 pointers
   Android, and probably iOS; 64bit ARM chips - will certainly not fork the OS
to
 use 64bit pointers

On these it appears that size_t will be (and should be) the pointer width.
 word/pointer width mismatch does happen, even if you try to argue it's
uncommon,
 the language MUST be able to express these architectures. It's not an optional
 fix. Just need to name them properly, and correct existing code.

What I think you're arguing for is a "most efficient" int size, which probably would be core.stdc.config.c_int, c_uint.
Feb 19 2012
prev sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 02/19/12 17:23, Manu wrote:
 On 19 February 2012 18:03, Vladimir Panteleev <vladimir thecybershadow.net
<mailto:vladimir thecybershadow.net>> wrote:
 
     On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:
 
         There is code that assumes size_t is the width of the pointer
 
 
     When is this not true? I can only think of 16-bit far pointers.
 
 
 Ignoring small embedded systems (for which it is almost always true), some
that immediately come to mind:
 
  NaCl (Google Native Client) - x64 arch, 32bit pointers ... <- of immediate
concern to me
  PPC based consoles; PS3, X360, Wii, WiiU (not released yet) - 64bit, all
32bit pointers
  Android, and probably iOS; 64bit ARM chips - will certainly not fork the OS
to use 64bit pointers

not to mention linux - x32 (https://sites.google.com/site/x32abi/) But 'size_t' is the size of an object -- so sizeof(size_t)==sizeof(void*) is a pretty safe assumption. It would be a bit hard to work with objects that are larger than the address space covered by the pointer... Is any of the above platforms using segmentation tricks and is sizeof(char*-char*)>sizeof(char*)? I think you mean "native_int" - something that D is missing. On 02/19/12 19:07, Timon Gehr wrote:
 Under which circumstances is it important to have a distinct type that denotes
the register size? What kind of code requires such a type? It is unportable.

eg any time you don't want to artificially restrict the size to less than the native one, not use a type wider than the hw efficiently handles or need C compatibility. Yes, you can use 'static if' and 'version' tricks, but that's inconvenient and often obfuscates the code, so you end up reinventing c_int/c_long... And that's not ideal either; having the right types [1] always predefined would be much better. On 02/19/12 18:26, Stewart Gordon wrote:
 If you want to know the size of an int, you would just use int.sizeof. 
Problem solved.

Exactly. Except doing this for D's int would be kind of pointless, wouldn't it?... With a native_int type you *can* write generic code and switch on native_int.sizeof. artur [1] ie a signed/unsigned int that is large as the CPU registers allow. [2] [2] and note that using anything smaller can result in performance degradation, if the values need to be converted to a full-width format.
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c7117959d6c7704b952cc29
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 17:09, Stewart Gordon <smjg_1998 yahoo.com> wrote:

 On 19/02/2012 14:59, Manu wrote:

 Okay, so it came up a couple of times, but the questions is, what are we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned
 halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed
 to be the same, which is a false assumption.

The whole point of size_t and ptrdiff_t is that they are integer types that span the address space. So that the size of an allocated block of memory (and consequently, the number of elements in an array) is bound to fit in a size_t, and the displacement between two memory locations is bound to fit in a ptrdiff_t. What would this "register size" type you are proposing be for, exactly?

You also need a type that knows the native word size of the machine, not just a pointer width. If size_t should be the pointer size, then there needs to be some other type that specifies the register width of the architecture.
 <snip>

  There is also the problem that there is lots of code written using the
 incorrect types.

Like what?

There is code that assumes size_t is the width of the pointer, and other code that assumes size_t is the width of the native int. Only one of those is correct, whichever you declare it to be, and another type needs to be invented to define the other. It is common that pointers are the same width as the int regs, but there are many architectures where it's not true. --00248c7117959d6c7704b952cc29 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 17:09, Stewart Gordon <span = dir=3D"ltr">&lt;<a href=3D"mailto:smjg_1998 yahoo.com">smjg_1998 yahoo.com<= /a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:= 0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 19/02/2012 14:59, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Okay, so it came up a couple of times, but the questions is, what are we go= ing to do about it?<br> <br> size_t and ptrdiff_t are incomplete, and represent non-complimentary signed= /unsigned<br> halves of the requirement.<br> There are TWO types needed, register size, and pointer size. Currently, the= se are assumed<br> to be the same, which is a false assumption.<br> </blockquote> <br></div> The whole point of size_t and ptrdiff_t is that they are integer types that= span the address space. =C2=A0So that the size of an allocated block of me= mory (and consequently, the number of elements in an array) is bound to fit= in a size_t, and the displacement between two memory locations is bound to= fit in a ptrdiff_t.<br> <br> What would this &quot;register size&quot; type you are proposing be for, ex= actly?<br></blockquote><div><br></div><div>You also need a type that knows = the native word size of the machine, not just a pointer width. If size_t sh= ould be the pointer size, then there needs to be some other type that speci= fies the register width of the architecture.</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex">&lt;snip&gt;<div class=3D"i= m"><br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> There is also the problem that there is lots of code written using the inco= rrect types.<br> </blockquote></div> &lt;snip&gt;<br> <br> Like what?<br> </blockquote></div><br><div>There is code that assumes size_t is the width = of the pointer, and other code that assumes size_t is the width of the nati= ve int. Only one of those is correct, whichever you declare it to be, and a= nother type needs to be invented to define the other.</div> <div>It is common that pointers are the same width as the int regs, but the= re are many architectures where it&#39;s not true.</div> --00248c7117959d6c7704b952cc29--
Feb 19 2012
prev sibling next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:
 There is code that assumes size_t is the width of the pointer

When is this not true? I can only think of 16-bit far pointers.
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c6a86e2ced94b04b9539966
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 18:03, Vladimir Panteleev
<vladimir thecybershadow.net>wrote:

 On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:

 There is code that assumes size_t is the width of the pointer

When is this not true? I can only think of 16-bit far pointers.

Ignoring small embedded systems (for which it is almost always true), some that immediately come to mind: NaCl (Google Native Client) - x64 arch, 32bit pointers ... <- of immediate concern to me PPC based consoles; PS3, X360, Wii, WiiU (not released yet) - 64bit, all 32bit pointers Android, and probably iOS; 64bit ARM chips - will certainly not fork the OS to use 64bit pointers word/pointer width mismatch does happen, even if you try to argue it's uncommon, the language MUST be able to express these architectures. It's not an optional fix. Just need to name them properly, and correct existing code. --00248c6a86e2ced94b04b9539966 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 18:03, Vladimir Panteleev <s= pan dir=3D"ltr">&lt;<a href=3D"mailto:vladimir thecybershadow.net">vladimir= thecybershadow.net</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quo= te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=

br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> There is code that assumes size_t is the width of the pointer<br> </blockquote> <br></div> When is this not true? I can only think of 16-bit far pointers.<br> </blockquote></div><br><div>Ignoring small embedded systems (for which it i= s almost always true), some that immediately come to mind:</div><div><br></= div><div>=C2=A0NaCl (Google Native Client) - x64 arch, 32bit pointers ... &= lt;-=C2=A0of immediate concern to me</div> <div>=C2=A0PPC based consoles; PS3, X360, Wii, WiiU (not released yet) - 64= bit, all 32bit pointers</div><div>=C2=A0Android, and probably iOS; 64bit AR= M chips - will certainly not fork the OS to use 64bit pointers</div><div><b= r></div> <div>word/pointer width mismatch does happen, even if you try to argue it&#= 39;s uncommon, the language MUST be able to express these architectures. It= &#39;s not an optional fix. Just need to name them properly, and correct ex= isting code.</div> --00248c6a86e2ced94b04b9539966--
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354530350f8e74004b9542a2b
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 18:31, Stewart Gordon <smjg_1998 yahoo.com> wrote:

 On 19/02/2012 15:26, Manu wrote:
 <snip>

 There is code that assumes size_t is the width of the pointer, and other
 code that assumes
 size_t is the width of the native int.

How does it do that? Indeed, how does code rely on the concept of native int at all?

You can't imagine any situation where you might want to know how big an int is? Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... Turn that question around... if you don't know the size of a native int, how do you propose you take advantage of it? --002354530350f8e74004b9542a2b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 18:31, Stewart Gordon <span = dir=3D"ltr">&lt;<a href=3D"mailto:smjg_1998 yahoo.com">smjg_1998 yahoo.com<= /a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:= 0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> On 19/02/2012 15:26, Manu wrote:<br> &lt;snip&gt;<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> There is code that assumes size_t is the width of the pointer, and other co= de that assumes<br> size_t is the width of the native int.<br> </blockquote> &lt;snip&gt;<br> <br> How does it do that?<br> <br> Indeed, how does code rely on the concept of native int at all?</blockquote=
<div><br></div><div>You can&#39;t imagine any situation where you might wa=

de, structure layout/packing, copying memory, basically optimising for 64bi= ts at all...</div> <div>Turn that question around... if you don&#39;t know the size of a nativ= e int, how do you propose you take advantage of it?</div></div> --002354530350f8e74004b9542a2b--
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354470c70bc435a04b954d3df
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 19:26, Stewart Gordon <smjg_1998 yahoo.com> wrote:

 On 19/02/2012 17:04, Manu wrote:
 <snip>

    Indeed, how does code rely on the concept of native int at all?

 You can't imagine any situation where you might want to know how big an
 int is?

Hang on ... are we talking here about some "native int", or the int type? If you want to know the size of a "native int", I think you would need to know more about how the particular machine works internally in order to take advantage of it.

In many cases you wouldn't need to know anything other than that. I don't really understand your resistance? I'm going to have the type when I need it, the question is, will it be standardised, or will I (& everyone else) invent the name and introduce a block of (probably not very portable) version() bullshit at the top of their module? Almost nobody here puts any thought towards portability, or any architecture other than x86+linux. I don't trust individuals writing their own version mess to define it correctly in their libraries... or to do it at all for that matter, they'll just be writing less portable code. Try this: Build phobos for x64, but define size_t as 32bits, and see what happens. You'll see what I'm talking about. --002354470c70bc435a04b954d3df Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 19:26, Stewart Gordon <span = dir=3D"ltr">&lt;<a href=3D"mailto:smjg_1998 yahoo.com">smjg_1998 yahoo.com<= /a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:= 0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> On 19/02/2012 17:04, Manu wrote:<br> &lt;snip&gt;<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im"> =C2=A0 =C2=A0Indeed, how does code rely on the concept of native int at al= l?<br> <br></div><div class=3D"im"> You can&#39;t imagine any situation where you might want to know how big an= int is?<br> </div></blockquote> &lt;snip&gt;<br> <br> Hang on ... are we talking here about some &quot;native int&quot;, or the i= nt type?<br> <br> If you want to know the size of a &quot;native int&quot;, I think you would= need to know more about how the particular machine works internally in ord= er to take advantage of it.</blockquote><div><br></div><div>In many cases y= ou wouldn&#39;t need to know anything other than that.</div> <div><br></div><div>I don&#39;t really understand your resistance? I&#39;m = going to have the type when I need it, the question is, will it be standard= ised, or will I (&amp; everyone else) invent the name and introduce a block= of (probably not very portable) version() bullshit at the top of their mod= ule?</div> <div>Almost nobody here puts any thought towards portability, or any archit= ecture other than x86+linux. I don&#39;t trust individuals writing their ow= n version mess to define it correctly in their libraries... or to do it at = all for that matter, they&#39;ll just be writing less portable code.</div> <div><br></div><div>Try this: Build phobos for x64, but define size_t as 32= bits, and see what happens. You&#39;ll see what I&#39;m talking about.</div=
</div>

--002354470c70bc435a04b954d3df--
Feb 19 2012
prev sibling next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the rest
 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.
Feb 19 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/19/2012 07:27 PM, Manu wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch
 <mailto:timon.gehr gmx.ch>> wrote:

     On 02/19/2012 03:59 PM, Manu wrote:

         Okay, so it came up a couple of times, but the questions is,
         what are we
         going to do about it?

         size_t and ptrdiff_t are incomplete, and represent non-complimentary
         signed/unsigned halves of the requirement.
         There are TWO types needed, register size, and pointer size.
         Currently,
         these are assumed to be the same, which is a false assumption.

         I propose size_t + ssize_t should both exist, and represent the
         native
         integer size. Also something like ptr_t, and ptrdiff_t should also
         exist, and represent the size of the pointer.

         Personally, I don't like the _t notation at all. It doesn't fit
         the rest
         of the D types, but it's established, so I don't expect it can
         change.
         But we do need the 2 missing types.

         There is also the problem that there is lots of code written
         using the
         incorrect types. Some time needs to be taken to correct phobos
         too I guess.


     Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is
     present, and what you call size_t/ssize_t does not exist. Under
     which circumstances is it important to have a distinct type that
     denotes the register size? What kind of code requires such a type?
     It is unportable.

Note that I agree that getting the terminology straight would be an overall improvement.
 It is just as unportable as size_t its self.

Currently, size_t is typeof(array.length). This is portable, and is basically the only place size_t commonly occurs in D code.
 The reason you need it is to improve portability, otherwise people need to
create arbitrary
 version mess, which will inevitably be incorrect.
 Anything from calling convention code, structure layout/packing, copying
 memory, basically optimising for 64bits at all... I can imagine static
 branches on the width of that type to select different paths.

That is not a very valid use case. In every static branch you'll know exactly what the width is.
 Even just basic efficiency, using 32bit ints on many 64bit machines
 require extra sign-extend opcodes after every single load... total waste
 of cpu time.

Using 64bit ints everywhere to represent 32bit ints won't make your program go faster. Cache lines fill up faster when the data contains large amounts of unnecessary padding. Furthermore, the compiler should be able to eliminate unneeded sign-extend operations. Anyway, extra sign-extend opcodes are not worth caring about if you get up to twice the number of conflict cache misses.
 Currently, if you're running a 64bit system with 32bit pointers, there
 is absolutely nothing that exists at compile time to tell you you're
 running a 64bit system,

Isn't there some version identifier for this? If there is not, such an identifier could be introduced trivially and this must be done.
 or to declare a variable of the machines native
 type, which you're crazy if you say is not important information.

What do you do with the machine's native type other than checking its size in a static if declaration? If you don't, then the code is unportable, and using the proper fixed size types would make it portable. If you do, then you could have checked a built-in version instead. What you effectively want for optimization is the most efficient type that is at least a certain number of bits wide. And even then, it is a moot point, because storing such variables in memory will add unnecessary padding to your data structures.
 What's the point of a 64bit machine, if you treat it exactly like a 32bit
 machine in every aspect?

There is none.
Feb 19 2012
prev sibling next sibling parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 20-02-2012 09:31, Iain Buclaw wrote:
 On 19 February 2012 18:27, Manu<turkeyman gmail.com>  wrote:
 On 19 February 2012 20:07, Timon Gehr<timon.gehr gmx.ch>  wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the rest
 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in every aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

IMHO, it should be. -- - Alex
Feb 20 2012
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 20/02/2012 17:21, Iain Buclaw wrote:
<snip>
 c_long and c_ulong are guaranteed to match target long size

Which means what, exactly? Stewart.
Feb 20 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-02-20 18:26, Stewart Gordon wrote:
 On 20/02/2012 17:21, Iain Buclaw wrote:
 <snip>
 c_long and c_ulong are guaranteed to match target long size

Which means what, exactly? Stewart.

Simplified: 32bit: Windows long == 32bit Posix long == 32bit 64bit: Windows long == 32bit Posix long == 64bit For a complete table of the 64bit data models see: http://en.wikipedia.org/wiki/64-bit#64-bit_data_models -- /Jacob Carlborg
Feb 20 2012
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 20/02/2012 19:11, Johannes Pfau wrote:
<snip>
 Exactly what's written there, c_long and c_ulong always match the C
 long/ulong types, whatever size those may be. It's mostly (only?)
 useful for C bindings.

So in other words, it just means whatever somebody has decreed that the "long" keyword in C shall mean on that platform. When did C gain a type called ulong, anyway? Are we going to have c_long_long as well? Stewart.
Feb 21 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 2:11 PM, Stewart Gordon wrote:
 When did C gain a type called ulong, anyway?

unsigned long
 Are we going to have c_long_long as well?

Probably.
Feb 21 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-02-22 06:24, Walter Bright wrote:
 On 2/21/2012 2:11 PM, Stewart Gordon wrote:
 When did C gain a type called ulong, anyway?

unsigned long
 Are we going to have c_long_long as well?

Probably.

Wouldn't that always be a "long" in D? Or is it the same as with "long" in C. -- /Jacob Carlborg
Feb 21 2012
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 22/02/2012 07:24, Jacob Carlborg wrote:
 On 2012-02-22 06:24, Walter Bright wrote:
 On 2/21/2012 2:11 PM, Stewart Gordon wrote:


 Are we going to have c_long_long as well?

Probably.

Wouldn't that always be a "long" in D? Or is it the same as with "long" in C.

long in D is 64 bits. long in C is 32 bits (on Win16/32 at least). If the C standard sets in stone the size of a long long, then we can do away with a c_long_long and just use long. Otherwise, if we're going to have c_int and c_long, it only makes sense to have c_long_long as well. Stewart.
Feb 22 2012
prev sibling parent reply Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
 c_long and c_ulong are guaranteed to match target long size (here
 would also go c_int and c_uint ;-).
 https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22

That is so good! Thanks! Currently, htod translates "unsigned long" to uint, which is wrong in linux 64 bits. Translating to size_t fixes that for linux, but I fear that a C "unsigned long" is not 64bit in all 64bit systems (windows): "About size_t and ptrdiff_t" http://www.codeproject.com/Articles/60082/About-size_t-and-ptrdiff_t Ran into this problem with mysql.h: typedef st_mysql_field { ... unsigned long length; unsigned long max_length; unsigned int name_length; ... } The only adequate fix, is your c_long that matches C's long. This is because uint doesn't change when in 64bit, and size_t fixes it for linux but maybe not for windows. The C standard only guarantees that: sizeof(char) <= sizeof(int) <= sizeof(long) <= sizeof(size_t) Which is insane. At some point in history, a C int meant the native register size for fast integer operations. But now C int seems to have been frozen to 32bits to avoid struct hell. So, in conclusion, my opinion is that there is no sane way of mapping C types to D types but to use something like your c_int, c_uint, c_long, c_ulong. Otherwise, the insanity of non-standard sizes and portability never stops. Love the intptr_t! A REQUEST: how about adding a c_size_t too? --jm
Feb 21 2012
next sibling parent reply Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
 Eh?

All the type sizes vary in broken ways in C. The only sane way to port C structs to D is to use c_<type> that has the size of the C compiler in the target platform. If there is a single C compiler has a different sized size_t than D's, then one has achieved nothing with the c_int, c_long, etc. So that is why it'd be nice, in my opinion, to have c_size_t (and c_ssize_t) if we are going to have c_int, c_long, etc. Sorry for requesting things though!! I still don't know my way around here. --jm On 02/21/2012 08:35 PM, Iain Buclaw wrote:
 On 21 February 2012 22:45, Juan Manuel Cabo <juanmanuel.cabo gmail.com> wrote:
 A REQUEST: how about adding a c_size_t too?

Eh?

Feb 21 2012
next sibling parent reply Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
 size_t is intended to be the C representation.  I very much do not want to end
up with a c_size_t.

Hahah, hold your jaw because it might drop: Looking for size_t extravagancies in C, I found that VC uses __int64 for size_t in x64 target. So this behaves differently according to the target: size_t s = -2; if (s < -1) { printf("An supposedly unsigned size_t is less than -1 in x64 ??"); } else { printf("all good, size_t is still unsigned"); } Though I don't ever expect to see a VC backend for D, this shows that anything can be expected from C. If you want to keep D's size_t unsigned, then let c_size_t do whatever C does, and let D use sane types that do what the documentation says. :-) --jm On 02/21/2012 09:10 PM, Sean Kelly wrote:
 On Feb 21, 2012, at 3:50 PM, Juan Manuel Cabo wrote:
 
 Eh?

All the type sizes vary in broken ways in C. The only sane way to port C structs to D is to use c_<type> that has the size of the C compiler in the target platform. If there is a single C compiler has a different sized size_t than D's, then one has achieved nothing with the c_int, c_long, etc. So that is why it'd be nice, in my opinion, to have c_size_t (and c_ssize_t) if we are going to have c_int, c_long, etc.

size_t is intended to be the C representation. I very much do not want to end up with a c_size_t. Are there times when D's size_t would be a different type? Also, I wonder how much code would break if we eliminated the size_t in object.di and replaced it with Size or whatever.

Feb 21 2012
next sibling parent Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
I'm sorry, my snippet is wrong. It's a bit more complicated than what I first
thought, and not even uniform between VC versions:

   "size_t definition and C4267 warning"
   social.msdn.microsoft.com/forums/en-US/vclanguage/thread/62d6df45-e8e4-4bb2-87e2-b3f8e85b4b37

--jm


On 02/21/2012 09:50 PM, Juan Manuel Cabo wrote:
 size_t is intended to be the C representation.  I very much do not want to end
up with a c_size_t.

Hahah, hold your jaw because it might drop: Looking for size_t extravagancies in C, I found that VC uses __int64 for size_t in x64 target. So this behaves differently according to the target: size_t s = -2; if (s < -1) { printf("An supposedly unsigned size_t is less than -1 in x64 ??"); } else { printf("all good, size_t is still unsigned"); } Though I don't ever expect to see a VC backend for D, this shows that anything can be expected from C. If you want to keep D's size_t unsigned, then let c_size_t do whatever C does, and let D use sane types that do what the documentation says. :-) --jm On 02/21/2012 09:10 PM, Sean Kelly wrote:
 On Feb 21, 2012, at 3:50 PM, Juan Manuel Cabo wrote:

 Eh?

All the type sizes vary in broken ways in C. The only sane way to port C structs to D is to use c_<type> that has the size of the C compiler in the target platform. If there is a single C compiler has a different sized size_t than D's, then one has achieved nothing with the c_int, c_long, etc. So that is why it'd be nice, in my opinion, to have c_size_t (and c_ssize_t) if we are going to have c_int, c_long, etc.

size_t is intended to be the C representation. I very much do not want to end up with a c_size_t. Are there times when D's size_t would be a different type? Also, I wonder how much code would break if we eliminated the size_t in object.di and replaced it with Size or whatever.


Feb 21 2012
prev sibling next sibling parent Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
On 02/21/2012 10:13 PM, Sean Kelly wrote:
 I think this is actually a good thing, since working with unsigned integers is
a pain.

Yes, I would prefer that msb bit to be the sign too, but behavior might depend on it, and correctness and predictability is important. My first code snippet was WRONG (sorry for the noise). And I couldn't even reproduce the problem with my VC. A correct snippet is simply this: size_t s = -2; if (s > 0) { printf("unsigned"); } else { printf("signed"); } Also, the shift operator is does a logical or arithmetic shift depending on whether it is signed or unsigned, so the result is different if you do s >> 1 whether s is signed or unsigned. THis is already nitpicky. I'm sorry for the noise. --jm
Feb 21 2012
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 4:50 PM, Juan Manuel Cabo wrote:
 Looking for size_t extravagancies in C, I found that VC uses __int64
 for size_t in x64 target.

Which is correct. size_t for 64 bit D is also a 64 bit integral type.
Feb 21 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 9:56 PM, Jonathan M Davis wrote:
 On Tuesday, February 21, 2012 21:22:54 Walter Bright wrote:
 On 2/21/2012 4:50 PM, Juan Manuel Cabo wrote:
 Looking for size_t extravagancies in C, I found that VC uses __int64
 for size_t in x64 target.

Which is correct. size_t for 64 bit D is also a 64 bit integral type.

Yes, but __int64 is a signed integeral type, whereas size_t in D is an unsigned integeral type.

Ah, I see.
Feb 21 2012
prev sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Feb 21, 2012, at 4:50 PM, Juan Manuel Cabo wrote:

 size_t is intended to be the C representation.  I very much do not =


=20
 Hahah, hold your jaw because it might drop:
=20
 Looking for size_t extravagancies in C, I found that VC uses __int64
 for size_t in x64 target.

I think this is actually a good thing, since working with unsigned = integers is a pain. I can't see any system needing that extra bit to = represent size any time soon anyway.=
Feb 21 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Feb 21, 2012, at 3:50 PM, Juan Manuel Cabo wrote:

 Eh?

All the type sizes vary in broken ways in C. The only sane way to port C structs to D is to use c_<type> that has the size of the C compiler in the target platform. =20 If there is a single C compiler has a different sized size_t than D's, then one has achieved nothing with the c_int, c_long, etc. =20 So that is why it'd be nice, in my opinion, to have c_size_t (and c_ssize_t) if we are going to have c_int, c_long, etc.

size_t is intended to be the C representation. I very much do not want = to end up with a c_size_t. Are there times when D's size_t would be a = different type? Also, I wonder how much code would break if we = eliminated the size_t in object.di and replaced it with Size or = whatever.=
Feb 21 2012
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 21/02/2012 22:45, Juan Manuel Cabo wrote:
<snip>
 The C standard only guarantees that:

    sizeof(char)<= sizeof(int)<= sizeof(long)<= sizeof(size_t)

I'm surprised. I'd assumed that, under 16-bit DOS/Windows, a size_t would be 16 bits. But no. Could memory blocks 64K or larger actually be allocated under those systems? Stewart.
Feb 21 2012
parent reply Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
I just went to see a standard draft
(http://www.clc-wiki.net/wiki/the_C_Standard)
to make sure, and it is even more convoluted than just that, but essentially the
same. Basically it says that chars must be at least
8bits and that shorts and ints must be able to represent at least 16 bits.

Then the ranks of the types are related to each other like that:
    rank(_Bool) < rank(char) < rank(short) < rank(int) < rank(long int) <
rank(long long int)
but rank is about conversion, not size, so while rank is strictly ordered,
sizeof types might not.

I didn't find size_t other than as the type of the value of sizeof()
expressions.

So, size_t is just standardized as the type of (sizeof(anystuff)).

I saw sizeof(long) <= sizeof(size_t)  in a website, but not on the standard.
So the standard doesn't even guarantee size_t being more than other
types, or the bigger type.

--jm


On 02/21/2012 10:23 PM, Stewart Gordon wrote:
 On 21/02/2012 22:45, Juan Manuel Cabo wrote:
 <snip>
 The C standard only guarantees that:

    sizeof(char)<= sizeof(int)<= sizeof(long)<= sizeof(size_t)

I'm surprised. I'd assumed that, under 16-bit DOS/Windows, a size_t would be 16 bits. But no. Could memory blocks 64K or larger actually be allocated under those systems? Stewart.

Feb 21 2012
parent reply Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
 I'm surprised.  I'd assumed that, under 16-bit DOS/Windows, a size_t would
 be 16 bits. But no.  Could memory blocks 64K  or larger actually be allocated
under those systems?


size_t being the typeof sizeof() expressions, tell you the upper bound for the size of static arrays, statically allocated: sizeof(buffer)/sizeof(int) has to be representable in a size_t. It tells you nothing else. What you can allocate dinamically depends on the architecture and how it lets you address it. 16bit intel had 16bit segments and offsets, so memory was segmented and you couldn't address more than 64kb at a time. So you couldn't have grabbed^H^H"allocated" more than 64kb in real mode in intel in a single linear block. --jm
Feb 21 2012
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/21/2012 6:07 PM, Juan Manuel Cabo wrote:
 16bit intel had 16bit segments and offsets, so memory was segmented
 and you couldn't address more than 64kb at a time.
 So you couldn't have grabbed^H^H"allocated" more than 64kb in real mode in
intel
 in a single linear block.

size_t was 16 bits on all 16 bit memory models except the 'huge' one.
Feb 21 2012
parent Don Clugston <dac nospam.com> writes:
On 22/02/12 06:16, Walter Bright wrote:
 On 2/21/2012 6:07 PM, Juan Manuel Cabo wrote:
 16bit intel had 16bit segments and offsets, so memory was segmented
 and you couldn't address more than 64kb at a time.
 So you couldn't have grabbed^H^H"allocated" more than 64kb in real
 mode in intel
 in a single linear block.

size_t was 16 bits on all 16 bit memory models except the 'huge' one.

I expected that for ptrdiff_t, but for size_t as well? So sizeof(int *) was larger than size_t ?
Feb 22 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354530350daaed204b955555c
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:

 On 02/19/2012 03:59 PM, Manu wrote:

 Okay, so it came up a couple of times, but the questions is, what are we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the rest
 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in every aspect? --002354530350daaed204b955555c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 20:07, Timon Gehr <span dir= =3D"ltr">&lt;<a href=3D"mailto:timon.gehr gmx.ch">timon.gehr gmx.ch</a>&gt;= </span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 02/19/2012 03:59 PM, Manu wrote:<br> </div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l= eft:1px #ccc solid;padding-left:1ex"><div class=3D"im"> Okay, so it came up a couple of times, but the questions is, what are we<br=

<br> size_t and ptrdiff_t are incomplete, and represent non-complimentary<br> signed/unsigned halves of the requirement.<br> There are TWO types needed, register size, and pointer size. Currently,<br> these are assumed to be the same, which is a false assumption.<br> <br></div><div class=3D"im"> I propose size_t + ssize_t should both exist, and represent the native<br> integer size. Also something like ptr_t, and ptrdiff_t should also<br> exist, and represent the size of the pointer.<br> <br> Personally, I don&#39;t like the _t notation at all. It doesn&#39;t fit the= rest<br> of the D types, but it&#39;s established, so I don&#39;t expect it can chan= ge.<br> But we do need the 2 missing types.<br> <br></div><div class=3D"im"> There is also the problem that there is lots of code written using the<br><= /div><div class=3D"im"> incorrect types. Some time needs to be taken to correct phobos too I guess.= <br> </div></blockquote> <br> Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is presen= t, and what you call size_t/ssize_t does not exist. Under which circumstanc= es is it important to have a distinct type that denotes the register size? = What kind of code requires such a type? It is unportable.<br> </blockquote></div><br><div>It is just as unportable as size_t its self. Th= e reason you need it is to improve portability, otherwise people need to cr= eate arbitrary version mess, which will inevitably be incorrect.</div> <div><div>Anything from calling convention code, structure layout/packing, = copying memory, basically optimising for 64bits at all... I can imagine sta= tic branches on the width of that type to select different paths.</div> </div><div>Even just basic efficiency, using 32bit ints on many 64bit machi= nes require extra sign-extend opcodes after every single load... total wast= e of cpu time. </div><div><br></div><div>Currently, if you&#39;re running a 64bit system w= ith 32bit pointers, there is absolutely nothing that exists at compile time= to tell you you&#39;re running a 64bit system, or to declare a variable of= the machines native type, which you&#39;re crazy if you say is not importa= nt information. What&#39;s the point of a 64bit machine, if you treat it ex= actly like a 32bit machine in every aspect?</div> --002354530350daaed204b955555c--
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--0023544713349b64c504b95784fa
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 21:21, Timon Gehr <timon.gehr gmx.ch> wrote:

 It is just as unportable as size_t its self.

Currently, size_t is typeof(array.length). This is portable, and is basically the only place size_t commonly occurs in D code.

What about pointer arithmetic? Interaction with C/C++ code? Writing OS level code? Hitting the hardware? And how do you define 'portable' in this context? What makes size_t more portable than a native int? A data structure containing a size_t is not 'portable' in the direct sense...
 The reason you need it is to improve portability, otherwise people need to
 create arbitrary
 version mess, which will inevitably be incorrect.
 Anything from calling convention code, structure layout/packing, copying
 memory, basically optimising for 64bits at all... I can imagine static
 branches on the width of that type to select different paths.

That is not a very valid use case. In every static branch you'll know exactly what the width is.

That's the point. Branches can each implement an efficient path for the different cases.
 Even just basic efficiency, using 32bit ints on many 64bit machines
 require extra sign-extend opcodes after every single load... total waste
 of cpu time.

program go faster. Cache lines fill up faster when the data contains large amounts of unnecessary padding. Furthermore, the compiler should be able to eliminate unneeded sign-extend operations. Anyway, extra sign-extend opcodes are not worth caring about if you get up to twice the number of conflict cache misses.

I'm talking about the stack, passing args etc. Data structures should obviously be as tight as possible.
 Currently, if you're running a 64bit system with 32bit pointers, there
 is absolutely nothing that exists at compile time to tell you you're
 running a 64bit system,

Isn't there some version identifier for this? If there is not, such an identifier could be introduced trivially and this must be done.

Why introduce a version identifier, when a type would be so much more useful, and also neater? (usable directly rather than ugly version blocks)
 or to declare a variable of the machines native
 type, which you're crazy if you say is not important information.

What do you do with the machine's native type other than checking its size in a static if declaration? If you don't, then the code is unportable, and using the proper fixed size types would make it portable. If you do, then you could have checked a built-in version instead. What you effectively want for optimization is the most efficient type that is at least a certain number of bits wide. And even then, it is a moot point, because storing such variables in memory will add unnecessary padding to your data structures.

If that's all you do with it, then it's already proven its worth. There's a major added bonus that you could USE it... I don't like this argument that it's not portable, it's exactly as portable as size_t is already, and there's no call to remove that.
 What's the point of a 64bit machine, if you treat it exactly like a 32bit
 machine in every aspect?

There is none.

Then why do so many hardware vendors feel the need to create 64bit chips which are used in 32bit memspace platforms? It's useful to have double width registers. Some algorithms are easier with wider registers, you can move more data faster, it extends your range for intermediate values during calculations, etc. These are still real advantages, even on a 32bit memspace platform. --0023544713349b64c504b95784fa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 19 February 2012 21:21, Timon Gehr <span dir= =3D"ltr">&lt;<a href=3D"mailto:timon.gehr gmx.ch">timon.gehr gmx.ch</a>&gt;= </span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex"><br>It is just as unportab= le as size_t its self.<br> </blockquote> <br></div> Currently, size_t is typeof(array.length). This is portable, and is basical= ly the only place size_t commonly occurs in D code.</blockquote><div><br></= div><div>What about pointer arithmetic? Interaction with C/C++ code? Writin= g OS level code? Hitting the hardware?</div> <div>And how do you define &#39;portable&#39; in this context? What makes s= ize_t more portable than a native int? A data structure containing a size_t= is not &#39;portable&#39; in the direct sense...</div><div>=C2=A0</div><bl= ockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #= ccc solid;padding-left:1ex"> <div class=3D"im"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex">The reason you need it is = to improve portability, otherwise people need to create arbitrary<br> version mess, which will inevitably be incorrect.<br> Anything from calling convention code, structure layout/packing, copying<br=

branches on the width of that type to select different paths.<br> </blockquote> <br></div> That is not a very valid use case. In every static branch you&#39;ll know e= xactly what the width is.</blockquote><div><br></div><div>That&#39;s the po= int.</div><div>Branches can each implement an efficient path for the differ= ent cases.</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"><blockquo= te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so= lid;padding-left:1ex"> Even just basic efficiency, using 32bit ints on many 64bit machines<br> require extra sign-extend opcodes after every single load... total waste<br=

<br> </blockquote> <br></div> Using 64bit ints everywhere to represent 32bit ints won&#39;t make your pro= gram go faster. Cache lines fill up faster when the data contains large amo= unts of unnecessary padding. Furthermore, the compiler should be able to el= iminate unneeded sign-extend operations. Anyway, extra sign-extend opcodes = are not worth caring about if you get up to twice the number of conflict ca= che misses.</blockquote> <div><br></div><div>I&#39;m talking about the stack, passing args etc. Data= structures should obviously be as tight as possible.</div><div>=C2=A0</div=
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1=

<div class=3D"im"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex">Currently, if you&#39;re r= unning a 64bit system with 32bit pointers, there<br> is absolutely nothing that exists at compile time to tell you you&#39;re<br=

</blockquote> <br></div> Isn&#39;t there some version identifier for this? If there is not, such an = identifier could be introduced trivially and this must be done.</blockquote=
<div><br></div><div>Why introduce a version identifier, when a type would =

ugly version blocks)</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"><blockquo= te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so= lid;padding-left:1ex"> or to declare a variable of the machines native<br> type, which you&#39;re crazy if you say is not important information.<br> </blockquote> <br></div> What do you do with the machine&#39;s native type other than checking its s= ize in a static if declaration? If you don&#39;t, then the code is unportab= le, and using the proper fixed size types would make it portable. If you do= , then you could have checked a built-in version instead. What you effectiv= ely want for optimization is the most efficient type that is at least a cer= tain number of bits wide. And even then, it is a moot point, because storin= g such variables in memory will add unnecessary padding to your data struct= ures.</blockquote> <div><br></div><div>If that&#39;s all you do with it, then it&#39;s already= proven its worth. There&#39;s a major added bonus that you could USE it...= </div><div>I don&#39;t like this argument that it&#39;s not portable, it&#3= 9;s exactly as portable as size_t is already, and there&#39;s no call to re= move that.</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"><blockquo= te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so= lid;padding-left:1ex"> What&#39;s the point of a 64bit machine, if you treat it exactly like a 32b= it<br> machine in every aspect?<br> </blockquote> <br></div> There is none.<br> </blockquote><div>=C2=A0</div><div>Then why do so many hardware vendors fee= l the need to create 64bit chips which are used in 32bit memspace platforms= ?</div><div>It&#39;s useful to have double width registers. Some algorithms= are easier with wider registers, you can move more data faster, it extends= your range for intermediate values during calculations, etc. These are sti= ll real advantages, even on a 32bit memspace platform.</div> </div> --0023544713349b64c504b95784fa--
Feb 19 2012
prev sibling next sibling parent reply kennytm <kennytm gmail.com> writes:
Manu <turkeyman gmail.com> wrote:
 I propose size_t + ssize_t should both exist, and represent the native
 integer size. 

sizediff_t (currently just aliased to ptrdiff_t but the link could be broken).
 Also something like ptr_t, and ptrdiff_t should also exist,
 and represent the size of the pointer.
 

core.stdc.stdint.uintptr_t
Feb 19 2012
parent reply Artur Skawina <art.08.09 gmail.com> writes:
On 02/20/12 00:17, Manu wrote:
 On 20 February 2012 01:10, kennytm <kennytm gmail.com
<mailto:kennytm gmail.com>> wrote:
 
     Manu <turkeyman gmail.com <mailto:turkeyman gmail.com>> wrote:
     > I propose size_t + ssize_t should both exist, and represent the native
     > integer size.
 
     sizediff_t (currently just aliased to ptrdiff_t but the link could be
     broken).
 
     > Also something like ptr_t, and ptrdiff_t should also exist,
     > and represent the size of the pointer.
     >
 
     core.stdc.stdint.uintptr_t
 
 
 O_o .. how is this different to size_t now? Why the redundant alias?

C compatibility? It is redundant in D, at least until it supports non-flat address spaces. :^) uintptr_t can hold a pointer, size_t only the size of something. These days there's usually not much difference, but take eg x86_16 segments - you can have several 'views' into memory, that allow for <= size_t-sized objects, but a full 'address' of such an object won't fit into a size_t. artur
Feb 19 2012
next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 19/02/2012 23:47, Artur Skawina wrote:
 On 02/20/12 00:17, Manu wrote:

      core.stdc.stdint.uintptr_t

 O_o .. how is this different to size_t now? Why the redundant alias?

C compatibility?

Why would you want to use meaningless type aliases defined in the C headers in D code?
 It is redundant in D, at least  until it supports non-flat address spaces. :^)

 uintptr_t can hold a pointer,

Why would you want to do that, as opposed to use one of the pointer types (which is indeed required for GC to work correctly)? Stewart.
Feb 19 2012
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
On 20/02/2012 03:44, Artur Skawina wrote:
<snip>
 Why would you want to do that, as opposed to use one of the pointer types
(which is
 indeed required for GC to work correctly)?

That's how it can be used in *C*. And the reason it needs to be exposed to D code is for interoperability with C.

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. Stewart.
Feb 20 2012
parent Artur Skawina <art.08.09 gmail.com> writes:
On 02/20/12 20:50, Manu wrote:
 On 20 February 2012 20:07, Artur Skawina <art.08.09 gmail.com
<mailto:art.08.09 gmail.com>> wrote:
 
     On 02/20/12 13:32, Stewart Gordon wrote:
     > On 20/02/2012 03:44, Artur Skawina wrote:
     > <snip>
     >>> Why would you want to do that, as opposed to use one of the pointer
types (which is
     >>> indeed required for GC to work correctly)?
     >>
     >> That's how it can be used in *C*.
     >>
     >> And the reason it needs to be exposed to D code is for interoperability
with C.
     >
     > 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.
 
     struct S { uintptr_t a; };
     extern (C) uintptr_t f(S* s, uintptr_t* blah);
 
     "uintptr_t" is not the best example here (because it will rarely appear in
C
     APIs), but still shows the problem - you need to know what it is -
otherwise
     you're left with guessing and eg assuming that uintptr==size_t.
 
     Fixing historical mistakes can be hard.
 
     There are basically three types of integer types:
 
     a) known fixed size types, such as a 32-bit wide unsigned int
     b) types, that are not explicitly sized, but meet certain criteria,
         eg: sizeof(short)<=sizeof(int)<=sizeof(long)
     c) externally defined types, which must always have the same
representation,
        the above uintptr_t example falls into this category.
 
     'C' didn't have the (a) types, so everybody had to redefine u8/s16/u32/s64
etc.
     'D' added these as builtin types so that problem was solved. Unfortunately,
     instead of eg using the de facto std s16/s32/s64, D reused short/int/long.
     'C's short/int/long were poorly (too loosely) defined, but what should have
     been done is defining them in 'D' as, for example:
 
     int:  efficient integer type, fitting in a CPU register and at least 32
bit wide;
 
 
 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.

Explicitly sized types (ie u32 and friends) is what should be used by default in any externally visible data structures. Yes, D's attempt at redefining int and long as fixed-size integers will cause confusion. But note that the compiler could help here, by disallowing any use of int and long in aggregates not marked with an 'internal' attribute. So a relatively safe migration path might be possible.
 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)
  
 
     long: efficient integer type, fitting in a CPU register and as wide as a
GPR.
 
 
 I don't think the term 'long' here, as opposed to 'int' draws this
distinction... so I really can't buy into this logic.
  
 
     Fixing things up now, with for example "nativeInt" (maps to "int" above)
and
     "widestInt" (the "long" above), is not easy. They are needed, that's why
     threads like this one appear, but simply adding them to the language or std
     library [1] wouldn't be enough. Why? Think literals, promotion and auto --
     I'm afraid programmers working with 'native' ints may not be expecting
     expressions evaluating to a narrower type.
 
     So there probably is no ideal simple solution for D2. For 64-bit platforms
and
     a future D3 language, the int/long, as defined above, would be a mostly
backward
     compatible change.
 
 
 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.
 People should only use these resizing types deliberately when they know what
they're doing.

I'd like to avoid using these long-named 'nativeInt' types when I know what I'm doing... ;) But, other than the 'int' and 'long' names, would such two types be enough? For D2 I'll probably end up aliasing them to something like rint/urint and wint/uwint anyway; short-term the question is only how to reliably find the alias source. artur
Feb 20 2012
prev sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 02/20/12 04:21, Stewart Gordon wrote:
 On 19/02/2012 23:47, Artur Skawina wrote:
 On 02/20/12 00:17, Manu wrote:

      core.stdc.stdint.uintptr_t

 O_o .. how is this different to size_t now? Why the redundant alias?

C compatibility?

Why would you want to use meaningless type aliases defined in the C headers in D code?

C compatibility?
 uintptr_t can hold a pointer,

Why would you want to do that, as opposed to use one of the pointer types (which is indeed required for GC to work correctly)?

That's how it can be used in *C*. And the reason it needs to be exposed to D code is for interoperability with C. artur
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00032557b58e7832c204b9595bb1
Content-Type: text/plain; charset=UTF-8

On 19 February 2012 23:16, Stewart Gordon <smjg_1998 yahoo.com> wrote:

 On 19/02/2012 17:51, Manu wrote:
 <snip>

    Hang on ... are we talking here about some "native int", or the int
 type?

I don't really understand your resistance? I'm going to have the type
 when I need it, the
 question is, will it be standardised, or will I (& everyone else) invent
 the name and
 introduce a block of (probably not very portable) version() bullshit at
 the top of their
 module?

I'm not saying we shouldn't have native integer types in D. Maybe what's needed is to be clearer on what's meant exactly by a native integer type. And then add the types to Phobos/druntime. I particularly don't understand your suggestion of the names "size_t" and "ssize_t" for these types. They don't seem to me to denote the size of anything. I guess "nativeInt" and "nativeUint", defined in whatever module would be suitable, would be one possibility. Maybe someone has a better idea.

well ssize_t is an already established compliment to size_t, I guess it's identical to ptrdiff_t, but some CRT's seem to prefer the ssize_t name. Personally size_t and ssize_t make more sense to me than size_t and ptrdiff_t, which seems like a contradiction of terminology, although the 'ptr' name seems more fitting to what it actually is... Ultimately I don't care, I suspect the prior commitment to size_t and ptrdiff_t can not be changed (although redefining their meaning would not be a breaking change, it just might show some cases of inappropriate usages) I agree that nativeInt should probably be in the standard library, but I'm really not into that name. It's really long and ugly. That said, I basically hate size_t too, it doesn't seem very D-ish, reeks of C mischief... and C stuffs up those types so much. It's not dependable what they actually mean in C (ie. ptr size/native word size) on all compilers I've come in contact with :/
 But knowing what code in Phobos/druntime should be using native integer
 types might help put the problem in better perspective.

 Stewart.

--00032557b58e7832c204b9595bb1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On 19 February 2012 23:16, Stewart Gordo= n <span dir=3D"ltr">&lt;<a href=3D"mailto:smjg_1998 yahoo.com">smjg_1998 ya= hoo.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D= "margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 19/02/2012 17:51, Manu wrote:<br> &lt;snip&gt;<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> =C2=A0 =C2=A0Hang on ... are we talking here about some &quot;native int&q= uot;, or the int type?<br> </blockquote></div> &lt;snip&gt;<div class=3D"im"><br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> I don&#39;t really understand your resistance? I&#39;m going to have the ty= pe when I need it, the<br> question is, will it be standardised, or will I (&amp; everyone else) inven= t the name and<br> introduce a block of (probably not very portable) version() bullshit at the= top of their<br> module?<br> </blockquote> <br></div> I&#39;m not saying we shouldn&#39;t have native integer types in D. =C2=A0M= aybe what&#39;s needed is to be clearer on what&#39;s meant exactly by a na= tive integer type. =C2=A0And then add the types to Phobos/druntime.<br> <br> I particularly don&#39;t understand your suggestion of the names &quot;size= _t&quot; and &quot;ssize_t&quot; for these types. =C2=A0They don&#39;t seem= to me to denote the size of anything. =C2=A0I guess &quot;nativeInt&quot; = and &quot;nativeUint&quot;, defined in whatever module would be suitable, w= ould be one possibility. =C2=A0Maybe someone has a better idea.<br> </blockquote><div><br></div><div>well ssize_t is an already established com= pliment to size_t, I guess it&#39;s identical to ptrdiff_t, but some CRT&#3= 9;s seem to prefer the ssize_t name. Personally size_t and ssize_t make mor= e sense to me than size_t and ptrdiff_t, which seems like a contradiction o= f terminology, although the &#39;ptr&#39; name seems more fitting to what i= t actually is...</div> <div><br></div><div>Ultimately I don&#39;t care, I suspect the prior commit= ment to size_t and ptrdiff_t can not be changed (although redefining their = meaning would not be a breaking change, it just might show some cases of in= appropriate usages)</div> <div>I agree that nativeInt should probably be in the standard library, but= I&#39;m really not into that name. It&#39;s really long and ugly. That sai= d, I basically hate size_t too, it doesn&#39;t seem very D-ish, reeks of C = mischief... and C stuffs up those types so much. It&#39;s not dependable wh= at they actually mean in C (ie. ptr size/native word size) on all compilers= I&#39;ve come in contact with :/</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex">But knowing what code in Ph= obos/druntime should be using native integer types might help put the probl= em in better perspective.<span class=3D"HOEnZb"><font color=3D"#888888"><br=

<br> Stewart.<br> </font></span></blockquote></div><br> --00032557b58e7832c204b9595bb1--
Feb 19 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c6a86e286326904b9596297
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 01:10, kennytm <kennytm gmail.com> wrote:

 Manu <turkeyman gmail.com> wrote:
 I propose size_t + ssize_t should both exist, and represent the native
 integer size.

sizediff_t (currently just aliased to ptrdiff_t but the link could be broken).
 Also something like ptr_t, and ptrdiff_t should also exist,
 and represent the size of the pointer.

core.stdc.stdint.uintptr_t

O_o .. how is this different to size_t now? Why the redundant alias? --00248c6a86e286326904b9596297 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 01:10, kennytm <span dir=3D"= ltr">&lt;<a href=3D"mailto:kennytm gmail.com">kennytm gmail.com</a>&gt;</sp= an> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;= border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">Manu &lt;<a href=3D"mailto:turkeyman gmail.com">turkeyman= gmail.com</a>&gt; wrote:<br> &gt; I propose size_t + ssize_t should both exist, and represent the native= <br> &gt; integer size.<br> <br> </div>sizediff_t (currently just aliased to ptrdiff_t but the link could be= <br> broken).<br> <div class=3D"im"><br> &gt; Also something like ptr_t, and ptrdiff_t should also exist,<br> &gt; and represent the size of the pointer.<br> &gt;<br> <br> </div>core.stdc.stdint.uintptr_t<br> </blockquote></div><br><div>O_o .. how is this different to size_t now? Why= the redundant alias?</div> --00248c6a86e286326904b9596297--
Feb 19 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the rest
 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in every aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~) -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354470c708296f704b9633b95
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 02:48, Walter Bright <newshound2 digitalmars.com> wrote:

 On 2/19/2012 3:15 PM, Manu wrote:

 Ultimately I don't care, I suspect the prior commitment to size_t and
 ptrdiff_t
 can not be changed (although redefining their meaning would not be a
 breaking
 change, it just might show some cases of inappropriate usages)
 I agree that nativeInt should probably be in the standard library, but I'm
 really not into that name. It's really long and ugly. That said, I
 basically
 hate size_t too, it doesn't seem very D-ish, reeks of C mischief... and C
 stuffs
 up those types so much. It's not dependable what they actually mean in C
 (ie.
 ptr size/native word size) on all compilers I've come in contact with :/

I really think that simply adding c_int and c_uint to core.stdc.config will solve the issue. After all, is there any case where the corresponding C int type would be different from a nativeInt?

? I must have misunderstood something... I've never seen a 64bit C compiler where 'int' is 64bits. --002354470c708296f704b9633b95 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 02:48, Walter Bright <span d= ir=3D"ltr">&lt;<a href=3D"mailto:newshound2 digitalmars.com">newshound2 dig= italmars.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" sty= le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 2/19/2012 3:15 PM, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Ultimately I don&#39;t care, I suspect the prior commitment to size_t and p= trdiff_t<br> can not be changed (although redefining their meaning would not be a breaki= ng<br> change, it just might show some cases of inappropriate usages)<br> I agree that nativeInt should probably be in the standard library, but I&#3= 9;m<br> really not into that name. It&#39;s really long and ugly. That said, I basi= cally<br> hate size_t too, it doesn&#39;t seem very D-ish, reeks of C mischief... and= C stuffs<br> up those types so much. It&#39;s not dependable what they actually mean in = C (ie.<br> ptr size/native word size) on all compilers I&#39;ve come in contact with := /<br> </blockquote> <br></div> I really think that simply adding c_int and c_uint to core.stdc.config will= solve the issue. After all, is there any case where the corresponding C in= t type would be different from a nativeInt?<br> </blockquote></div><br><div>? I must have misunderstood something...=C2=A0I= &#39;ve never seen a 64bit C compiler where &#39;int&#39; is 64bits.</div> --002354470c708296f704b9633b95--
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c6a86e254347304b9636621
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are



 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size. Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the



 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version

 which will inevitably be incorrect.
 Anything from calling convention code, structure layout/packing, copying
 memory, basically optimising for 64bits at all... I can imagine static
 branches on the width of that type to select different paths.
 Even just basic efficiency, using 32bit ints on many 64bit machines

 extra sign-extend opcodes after every single load... total waste of cpu
 time.

 Currently, if you're running a 64bit system with 32bit pointers, there is
 absolutely nothing that exists at compile time to tell you you're

 64bit system, or to declare a variable of the machines native type, which
 you're crazy if you say is not important information. What's the point

 64bit machine, if you treat it exactly like a 32bit machine in every

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type that represents them? :) My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems the intent is to go out of the way to maintain compatibility with C, at the expense of sucking C's messy and poorly defined types into D, which is a shame. It just results in D having the same crappy archaic typing problems as C. I appreciate that the C types should exist for interoperability with C (ie, their quirks should be preserved for any given compiler/architecture), but I'd also like to see strictly defined types in D with no respect to any C counterpart, guaranteed by the language to be exactly what they claim to be, and not confused depending which compiler you try to use. These 2 GCC intrinsics would appear to be precisely what I was looking for at the start of this thread... --00248c6a86e254347304b9636621 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 10:31, Iain Buclaw <span dir= =3D"ltr">&lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw ubuntu.com</a>&g= t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0= .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 19 February 2012 18:27, Manu &lt= ;<a href=3D"mailto:turkeyman gmail.com">turkeyman gmail.com</a>&gt; wrote:<= br> &gt; On 19 February 2012 20:07, Timon Gehr &lt;<a href=3D"mailto:timon.gehr= gmx.ch">timon.gehr gmx.ch</a>&gt; wrote:<br> &gt;&gt;<br> &gt;&gt; On 02/19/2012 03:59 PM, Manu wrote:<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Okay, so it came up a couple of times, but the questions is, w= hat are we<br> &gt;&gt;&gt; going to do about it?<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; size_t and ptrdiff_t are incomplete, and represent non-complim= entary<br> &gt;&gt;&gt; signed/unsigned halves of the requirement.<br> &gt;&gt;&gt; There are TWO types needed, register size, and pointer size. C= urrently,<br> &gt;&gt;&gt; these are assumed to be the same, which is a false assumption.= <br> &gt;&gt;&gt;<br> &gt;&gt;&gt; I propose size_t + ssize_t should both exist, and represent th= e native<br> &gt;&gt;&gt; integer size. Also something like ptr_t, and ptrdiff_t should = also<br> &gt;&gt;&gt; exist, and represent the size of the pointer.<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Personally, I don&#39;t like the _t notation at all. It doesn&= #39;t fit the rest<br> &gt;&gt;&gt; of the D types, but it&#39;s established, so I don&#39;t expec= t it can change.<br> &gt;&gt;&gt; But we do need the 2 missing types.<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; There is also the problem that there is lots of code written u= sing the<br> &gt;&gt;&gt; incorrect types. Some time needs to be taken to correct phobos= too I<br> &gt;&gt;&gt; guess.<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; Currently, size_t is defined to be what you call ptr_t, ptrdiff_t = is<br> &gt;&gt; present, and what you call size_t/ssize_t does not exist. Under wh= ich<br> &gt;&gt; circumstances is it important to have a distinct type that denotes= the<br> &gt;&gt; register size? What kind of code requires such a type? It is unpor= table.<br> &gt;<br> &gt;<br> &gt; It is just as unportable as size_t its self. The reason you need it is= to<br> &gt; improve portability, otherwise people need to create arbitrary version= mess,<br> &gt; which will inevitably be incorrect.<br> &gt; Anything from calling convention code, structure layout/packing, copyi= ng<br> &gt; memory, basically optimising for 64bits at all... I can imagine static= <br> &gt; branches on the width of that type to select different paths.<br> &gt; Even just basic efficiency, using 32bit ints on many 64bit machines re= quire<br> &gt; extra sign-extend opcodes after every single load... total waste of cp= u<br> &gt; time.<br> &gt;<br> &gt; Currently, if you&#39;re running a 64bit system with 32bit pointers, t= here is<br> &gt; absolutely nothing that exists at compile time to tell you you&#39;re = running a<br> &gt; 64bit system, or to declare a variable of the machines native type, wh= ich<br> &gt; you&#39;re crazy if you say is not important information. What&#39;s t= he point of a<br> &gt; 64bit machine, if you treat it exactly like a 32bit machine in every a= spect?<br> <br> </div></div>gdc offers __builtin_machine_(u)int for word size, and<br> __builtin_pointer_(u)int for pointer size via gcc.builtins module.<br> Nevermind though, it&#39;s not quite a &quot;standard&quot; :~)<br></blockq= uote><div><br></div><div>That&#39;s beautiful though! Can we alias them, an= d produce a true D type that represents them? :)</div><div><br></div><div> My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems= the intent is to go out of the way to maintain compatibility with C, at th= e expense of sucking C&#39;s messy and poorly defined types into D, which i= s a shame. It just results in D having the same crappy archaic typing probl= ems as C.</div> <div>I appreciate that the C types should exist for interoperability with C= (ie, their quirks should be preserved for any given compiler/architecture)= , but I&#39;d also like to see strictly defined types in D with no respect = to any C counterpart, guaranteed by the language to be exactly what they cl= aim to be, and not confused depending which compiler you try to use.</div> <div><br></div><div>These 2 GCC intrinsics would appear to be precisely wha= t I was looking for at the start of this thread...</div></div> --00248c6a86e254347304b9636621--
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--002354530350e6a48d04b96398aa
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 13:16, Walter Bright <newshound2 digitalmars.com> wrote:

 On 2/20/2012 3:02 AM, Manu wrote:

 ? I must have misunderstood something... I've never seen a 64bit C
 compiler
 where 'int' is 64bits.

What are you using in C code for a most efficient integer type?

#ifdef. No 2 C compilers ever seem to agree. It's a major problem in C, hence bringing it up here. Even size_t is often broken in C. I have worked on 64bit systems with 32bit pointers where size_t was still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe my memory fails me) I want to be confident when I declare a numeric type that can interact with pointers, and also when I want the native type. --002354530350e6a48d04b96398aa Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 13:16, Walter Bright <span d= ir=3D"ltr">&lt;<a href=3D"mailto:newshound2 digitalmars.com">newshound2 dig= italmars.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" sty= le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 2/20/2012 3:02 AM, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> ? I must have misunderstood something... I&#39;ve never seen a 64bit C comp= iler<br> where &#39;int&#39; is 64bits.<br> </blockquote> <br></div> What are you using in C code for a most efficient integer type?<br> </blockquote></div><br><div>#ifdef. No 2 C compilers ever seem to agree.</d= iv><div>It&#39;s a major problem in C, hence bringing it up here. Even size= _t is often broken in C. I have worked on 64bit systems with 32bit pointers= where size_t was still 64bit, but ptrdiff_t was 32bit (I think PS3 is like= this, but maybe my memory fails me)</div> <div><br></div><div>I want to be confident when I declare a numeric type th= at can interact with pointers, and also when I want the native type.</div> --002354530350e6a48d04b96398aa--
Feb 20 2012
prev sibling next sibling parent "Regan Heath" <regan netmail.co.nz> writes:
On Mon, 20 Feb 2012 11:28:44 -0000, Manu <turkeyman gmail.com> wrote:

 On 20 February 2012 13:16, Walter Bright <newshound2 digitalmars.com>  
 wrote:

 On 2/20/2012 3:02 AM, Manu wrote:

 ? I must have misunderstood something... I've never seen a 64bit C
 compiler
 where 'int' is 64bits.

What are you using in C code for a most efficient integer type?

#ifdef. No 2 C compilers ever seem to agree. It's a major problem in C, hence bringing it up here. Even size_t is often broken in C. I have worked on 64bit systems with 32bit pointers where size_t was still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe my memory fails me) I want to be confident when I declare a numeric type that can interact with pointers, and also when I want the native type.

I can imagine situations where you want to explicitly have a numeric type that can hold/interact with pointers, or you need /more/ width than the native/efficient int type. But, in /all/ other cases surely we want the **compiler** to pick/use the native/most efficient int type/size. Further, why should we state this explicitly, why shouldn't "int" just /be/ the native/most efficient type (as determined by the compiler during compilation of each/every block of code)... I know, I know, this goes in the face of one of D's initial design decisions - being sure of the width of your types without having to guess or dig in headers for defines etc.. but, remind me why this is a bad idea? Because, it just seems to me that we want "int" to be the native/most efficient type and we want fixed sized types for special/specific cases (like in struct definitions where alignment/size matters, etc), i.e. int a; // native/efficient type int16 b; // 16 bit int int32 c; // 32 bit int int64 d; // 64 bit int ..and so on.. But.. assuming that's not going to change any time soon, we might be able to go the other way. What if we had a built-in "nint" type, which we could use everywhere we didn't care about integer type width, which resulted in the compiler picking the most efficient/native int width on a case by case basis (code inspection, etc.. not sure of the limits of this). Regan -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Feb 20 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 20 February 2012 11:14, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what are
 we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size.
 Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the
 rest
 of the D types, but it's established, so I don't expect it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using the
 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in every aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type that represents them? :) My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems the intent is to go out of the way to maintain compatibility with C, at the expense of sucking C's messy and poorly defined types into D, which is a shame. It just results in D having the same crappy archaic typing problems as C. I appreciate that the C types should exist for interoperability with C (ie, their quirks should be preserved for any given compiler/architecture), but I'd also like to see strictly defined types in D with no respect to any C counterpart, guaranteed by the language to be exactly what they claim to be, and not confused depending which compiler you try to use. These 2 GCC intrinsics would appear to be precisely what I was looking for at the start of this thread...

Well, as Walter said, these could be aliased in core.stdc.config. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Feb 20 2012
prev sibling next sibling parent Kevin Cox <kevincox.ca gmail.com> writes:
--0015175d04bcb0e9dc04b965ef87
Content-Type: text/plain; charset=UTF-8

What if te compiler was allowed to optimist to larger types?  The only
issue is if pulled rely on overflowing.  That could be fixed by add in a
type with a minimum size specified.  This is kind of like C's fast int type.
On Feb 20, 2012 8:20 AM, "Regan Heath" <regan netmail.co.nz> wrote:

 On Mon, 20 Feb 2012 11:28:44 -0000, Manu <turkeyman gmail.com> wrote:

  On 20 February 2012 13:16, Walter Bright <newshound2 digitalmars.com>
 wrote:

  On 2/20/2012 3:02 AM, Manu wrote:
  ? I must have misunderstood something... I've never seen a 64bit C
 compiler
 where 'int' is 64bits.


It's a major problem in C, hence bringing it up here. Even size_t is often broken in C. I have worked on 64bit systems with 32bit pointers where size_t was still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe my memory fails me) I want to be confident when I declare a numeric type that can interact with pointers, and also when I want the native type.

I can imagine situations where you want to explicitly have a numeric type that can hold/interact with pointers, or you need /more/ width than the native/efficient int type. But, in /all/ other cases surely we want the **compiler** to pick/use the native/most efficient int type/size. Further, why should we state this explicitly, why shouldn't "int" just /be/ the native/most efficient type (as determined by the compiler during compilation of each/every block of code)... I know, I know, this goes in the face of one of D's initial design decisions - being sure of the width of your types without having to guess or dig in headers for defines etc.. but, remind me why this is a bad idea? Because, it just seems to me that we want "int" to be the native/most efficient type and we want fixed sized types for special/specific cases (like in struct definitions where alignment/size matters, etc), i.e. int a; // native/efficient type int16 b; // 16 bit int int32 c; // 32 bit int int64 d; // 64 bit int ..and so on.. But.. assuming that's not going to change any time soon, we might be able to go the other way. What if we had a built-in "nint" type, which we could use everywhere we didn't care about integer type width, which resulted in the compiler picking the most efficient/native int width on a case by case basis (code inspection, etc.. not sure of the limits of this). Regan -- Using Opera's revolutionary email client: http://www.opera.com/mail/

--0015175d04bcb0e9dc04b965ef87 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p>What if te compiler was allowed to optimist to larger types?=C2=A0 The o= nly issue is if pulled rely on overflowing.=C2=A0 That could be fixed by ad= d in a type with a minimum size specified.=C2=A0 This is kind of like C&#39= ;s fast int type.</p> <div class=3D"gmail_quote">On Feb 20, 2012 8:20 AM, &quot;Regan Heath&quot;= &lt;<a href=3D"mailto:regan netmail.co.nz">regan netmail.co.nz</a>&gt; wro= te:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"marg= in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> On Mon, 20 Feb 2012 11:28:44 -0000, Manu &lt;<a href=3D"mailto:turkeyman gm= ail.com" target=3D"_blank">turkeyman gmail.com</a>&gt; wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 20 February 2012 13:16, Walter Bright &lt;<a href=3D"mailto:newshound2 d= igitalmars.com" target=3D"_blank">newshound2 digitalmars.com</a>&gt; wrote:= <br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 2/20/2012 3:02 AM, Manu wrote:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> ? I must have misunderstood something... I&#39;ve never seen a 64bit C<br> compiler<br> where &#39;int&#39; is 64bits.<br> <br> </blockquote> <br> What are you using in C code for a most efficient integer type?<br> <br> </blockquote> <br> #ifdef. No 2 C compilers ever seem to agree.<br> It&#39;s a major problem in C, hence bringing it up here. Even size_t is of= ten<br> broken in C. I have worked on 64bit systems with 32bit pointers where<br> size_t was still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this,<= br> but maybe my memory fails me)<br> <br> I want to be confident when I declare a numeric type that can interact with= <br> pointers, and also when I want the native type.<br> </blockquote> <br> I can imagine situations where you want to explicitly have a numeric type t= hat can hold/interact with pointers, or you need /more/ width than the nati= ve/efficient int type.<br> <br> But, in /all/ other cases surely we want the **compiler** to pick/use the n= ative/most efficient int type/size. =C2=A0Further, why should we state this= explicitly, why shouldn&#39;t &quot;int&quot; just /be/ the native/most ef= ficient type (as determined by the compiler during compilation of each/ever= y block of code)... I know, I know, this goes in the face of one of D&#39;s= initial design decisions - being sure of the width of your types without h= aving to guess or dig in headers for defines etc.. but, remind me why this = is a bad idea?<br> <br> Because, it just seems to me that we want &quot;int&quot; to be the native/= most efficient type and we want fixed sized types for special/specific case= s (like in struct definitions where alignment/size matters, etc), i.e.<br> <br> int a; =C2=A0 // native/efficient type<br> int16 b; // 16 bit int<br> int32 c; // 32 bit int<br> int64 d; // 64 bit int<br> ..and so on..<br> <br> But.. assuming that&#39;s not going to change any time soon, we might be ab= le to go the other way. =C2=A0What if we had a built-in &quot;nint&quot; ty= pe, which we could use everywhere we didn&#39;t care about integer type wid= th, which resulted in the compiler picking the most efficient/native int wi= dth on a case by case basis (code inspection, etc.. not sure of the limits = of this).<br> <br> Regan<br> <br> -- <br> Using Opera&#39;s revolutionary email client: <a href=3D"http://www.opera.c= om/mail/" target=3D"_blank">http://www.opera.com/mail/</a><br> </blockquote></div> --0015175d04bcb0e9dc04b965ef87--
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c768f9efb19c204b967ad27
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 16:03, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On 20 February 2012 11:14, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what





 we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size.
 Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the





 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the
 rest
 of the D types, but it's established, so I don't expect it can





 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using





 incorrect types. Some time needs to be taken to correct phobos too I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes




 register size? What kind of code requires such a type? It is
 unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing,



 memory, basically optimising for 64bits at all... I can imagine static
 branches on the width of that type to select different paths.
 Even just basic efficiency, using 32bit ints on many 64bit machines
 require
 extra sign-extend opcodes after every single load... total waste of



 time.

 Currently, if you're running a 64bit system with 32bit pointers, there
 is
 absolutely nothing that exists at compile time to tell you you're
 running a
 64bit system, or to declare a variable of the machines native type,
 which
 you're crazy if you say is not important information. What's the point
 of a
 64bit machine, if you treat it exactly like a 32bit machine in every
 aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type

 represents them? :)

 My basic issue with these size_t/c_int/core.stdc... stuff, is that it

 the intent is to go out of the way to maintain compatibility with C, at

 expense of sucking C's messy and poorly defined types into D, which is a
 shame. It just results in D having the same crappy archaic typing

 as C.
 I appreciate that the C types should exist for interoperability with C

 their quirks should be preserved for any given compiler/architecture),

 I'd also like to see strictly defined types in D with no respect to any C
 counterpart, guaranteed by the language to be exactly what they claim to

 and not confused depending which compiler you try to use.

 These 2 GCC intrinsics would appear to be precisely what I was looking

 at the start of this thread...

Well, as Walter said, these could be aliased in core.stdc.config.

I don't think they are 'standard c' though ;) --00248c768f9efb19c204b967ad27 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 16:03, Iain Buclaw <span dir= =3D"ltr">&lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw ubuntu.com</a>&g= t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0= .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 20 February 2012 11:14, Manu &lt= ;<a href=3D"mailto:turkeyman gmail.com">turkeyman gmail.com</a>&gt; wrote:<= br> &gt; On 20 February 2012 10:31, Iain Buclaw &lt;<a href=3D"mailto:ibuclaw u= buntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt;&gt;<br> &gt;&gt; On 19 February 2012 18:27, Manu &lt;<a href=3D"mailto:turkeyman gm= ail.com">turkeyman gmail.com</a>&gt; wrote:<br> &gt;&gt; &gt; On 19 February 2012 20:07, Timon Gehr &lt;<a href=3D"mailto:t= imon.gehr gmx.ch">timon.gehr gmx.ch</a>&gt; wrote:<br> &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; On 02/19/2012 03:59 PM, Manu wrote:<br> &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt;&gt; Okay, so it came up a couple of times, but the questi= ons is, what are<br> &gt;&gt; &gt;&gt;&gt; we<br> &gt;&gt; &gt;&gt;&gt; going to do about it?<br> &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt;&gt; size_t and ptrdiff_t are incomplete, and represent no= n-complimentary<br> &gt;&gt; &gt;&gt;&gt; signed/unsigned halves of the requirement.<br> &gt;&gt; &gt;&gt;&gt; There are TWO types needed, register size, and pointe= r size.<br> &gt;&gt; &gt;&gt;&gt; Currently,<br> &gt;&gt; &gt;&gt;&gt; these are assumed to be the same, which is a false as= sumption.<br> &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt;&gt; I propose size_t + ssize_t should both exist, and rep= resent the native<br> &gt;&gt; &gt;&gt;&gt; integer size. Also something like ptr_t, and ptrdiff_= t should also<br> &gt;&gt; &gt;&gt;&gt; exist, and represent the size of the pointer.<br> &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt;&gt; Personally, I don&#39;t like the _t notation at all. = It doesn&#39;t fit the<br> &gt;&gt; &gt;&gt;&gt; rest<br> &gt;&gt; &gt;&gt;&gt; of the D types, but it&#39;s established, so I don&#3= 9;t expect it can change.<br> &gt;&gt; &gt;&gt;&gt; But we do need the 2 missing types.<br> &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt;&gt; There is also the problem that there is lots of code = written using the<br> &gt;&gt; &gt;&gt;&gt; incorrect types. Some time needs to be taken to corre= ct phobos too I<br> &gt;&gt; &gt;&gt;&gt; guess.<br> &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; Currently, size_t is defined to be what you call ptr_t, p= trdiff_t is<br> &gt;&gt; &gt;&gt; present, and what you call size_t/ssize_t does not exist.= Under which<br> &gt;&gt; &gt;&gt; circumstances is it important to have a distinct type tha= t denotes the<br> &gt;&gt; &gt;&gt; register size? What kind of code requires such a type? It= is<br> &gt;&gt; &gt;&gt; unportable.<br> &gt;&gt; &gt;<br> &gt;&gt; &gt;<br> &gt;&gt; &gt; It is just as unportable as size_t its self. The reason you n= eed it is<br> &gt;&gt; &gt; to<br> &gt;&gt; &gt; improve portability, otherwise people need to create arbitrar= y version<br> &gt;&gt; &gt; mess,<br> &gt;&gt; &gt; which will inevitably be incorrect.<br> &gt;&gt; &gt; Anything from calling convention code, structure layout/packi= ng, copying<br> &gt;&gt; &gt; memory, basically optimising for 64bits at all... I can imagi= ne static<br> &gt;&gt; &gt; branches on the width of that type to select different paths.= <br> &gt;&gt; &gt; Even just basic efficiency, using 32bit ints on many 64bit ma= chines<br> &gt;&gt; &gt; require<br> &gt;&gt; &gt; extra sign-extend opcodes after every single load... total wa= ste of cpu<br> &gt;&gt; &gt; time.<br> &gt;&gt; &gt;<br> &gt;&gt; &gt; Currently, if you&#39;re running a 64bit system with 32bit po= inters, there<br> &gt;&gt; &gt; is<br> &gt;&gt; &gt; absolutely nothing that exists at compile time to tell you yo= u&#39;re<br> &gt;&gt; &gt; running a<br> &gt;&gt; &gt; 64bit system, or to declare a variable of the machines native= type,<br> &gt;&gt; &gt; which<br> &gt;&gt; &gt; you&#39;re crazy if you say is not important information. Wha= t&#39;s the point<br> &gt;&gt; &gt; of a<br> &gt;&gt; &gt; 64bit machine, if you treat it exactly like a 32bit machine i= n every<br> &gt;&gt; &gt; aspect?<br> &gt;&gt;<br> &gt;&gt; gdc offers __builtin_machine_(u)int for word size, and<br> &gt;&gt; __builtin_pointer_(u)int for pointer size via gcc.builtins module.= <br> &gt;&gt; Nevermind though, it&#39;s not quite a &quot;standard&quot; :~)<br=

&gt;<br> &gt; That&#39;s beautiful though! Can we alias them, and produce a true D t= ype that<br> &gt; represents them? :)<br> &gt;<br> &gt; My basic issue with these size_t/c_int/core.stdc... stuff, is that it = seems<br> &gt; the intent is to go out of the way to maintain compatibility with C, a= t the<br> &gt; expense of sucking C&#39;s messy and poorly defined types into D, whic= h is a<br> &gt; shame. It just results in D having the same crappy archaic typing prob= lems<br> &gt; as C.<br> &gt; I appreciate that the C types should exist for interoperability with C= (ie,<br> &gt; their quirks should be preserved for any given compiler/architecture),= but<br> &gt; I&#39;d also like to see strictly defined types in D with no respect t= o any C<br> &gt; counterpart, guaranteed by the language to be exactly what they claim = to be,<br> &gt; and not confused depending which compiler you try to use.<br> &gt;<br> &gt; These 2 GCC intrinsics would appear to be precisely what I was looking= for<br> &gt; at the start of this thread...<br> <br> <br> </div></div>Well, as Walter said, these could be aliased in core.stdc.confi= g.<br></blockquote><div><br></div><div>I don&#39;t think they are &#39;stan= dard c&#39; though ;)</div></div> --00248c768f9efb19c204b967ad27--
Feb 20 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 20 February 2012 16:20, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 16:03, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 20 February 2012 11:14, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what
 are
 we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent
 non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size.
 Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the
 native
 integer size. Also something like ptr_t, and ptrdiff_t should also
 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit the
 rest
 of the D types, but it's established, so I don't expect it can
 change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written using
 the
 incorrect types. Some time needs to be taken to correct phobos too
 I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t is present, and what you call size_t/ssize_t does not exist. Under which circumstances is it important to have a distinct type that denotes the register size? What kind of code requires such a type? It is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in every aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type that represents them? :) My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems the intent is to go out of the way to maintain compatibility with C, at the expense of sucking C's messy and poorly defined types into D, which is a shame. It just results in D having the same crappy archaic typing problems as C. I appreciate that the C types should exist for interoperability with C (ie, their quirks should be preserved for any given compiler/architecture), but I'd also like to see strictly defined types in D with no respect to any C counterpart, guaranteed by the language to be exactly what they claim to be, and not confused depending which compiler you try to use. These 2 GCC intrinsics would appear to be precisely what I was looking for at the start of this thread...

Well, as Walter said, these could be aliased in core.stdc.config.

I don't think they are 'standard c' though ;)

OK, I'm just having a trudge through druntime: intptr_t and uintptr_t are guaranteed to match pointer size. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stdint.d#cl-70 c_long and c_ulong are guaranteed to match target long size (here would also go c_int and c_uint ;-). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22 This needs fixing, as wchar_t may not be same size across all targets (some change size of wchar_t based on compile time switches). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stddef.d#cl-28 This needs fixing, as wint_t may not be same size across all targets. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/wchar_.d#cl-29 -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Feb 20 2012
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Mon, 20 Feb 2012 17:26:53 +0000
schrieb Stewart Gordon <smjg_1998 yahoo.com>:

 On 20/02/2012 17:21, Iain Buclaw wrote:
 <snip>
 c_long and c_ulong are guaranteed to match target long size

Which means what, exactly? Stewart.

Exactly what's written there, c_long and c_ulong always match the C long/ulong types, whatever size those may be. It's mostly (only?) useful for C bindings.
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c7117955c2b1a04b96a82f9
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 19:21, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On 20 February 2012 16:20, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 16:03, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 20 February 2012 11:14, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch> wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions is, what
 are
 we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent
 non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer size.
 Currently,
 these are assumed to be the same, which is a false assumption.

 I propose size_t + ssize_t should both exist, and represent the
 native
 integer size. Also something like ptr_t, and ptrdiff_t should







 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It doesn't fit







 rest
 of the D types, but it's established, so I don't expect it can
 change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code written







 the
 incorrect types. Some time needs to be taken to correct phobos







 I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t






 present, and what you call size_t/ssize_t does not exist. Under
 which
 circumstances is it important to have a distinct type that denotes
 the
 register size? What kind of code requires such a type? It is
 unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in





 aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type that represents them? :) My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems the intent is to go out of the way to maintain compatibility with C,



 the
 expense of sucking C's messy and poorly defined types into D, which



 shame. It just results in D having the same crappy archaic typing
 problems
 as C.
 I appreciate that the C types should exist for interoperability with C
 (ie,
 their quirks should be preserved for any given compiler/architecture),
 but
 I'd also like to see strictly defined types in D with no respect to



 C
 counterpart, guaranteed by the language to be exactly what they claim



 be,
 and not confused depending which compiler you try to use.

 These 2 GCC intrinsics would appear to be precisely what I was looking
 for
 at the start of this thread...

Well, as Walter said, these could be aliased in core.stdc.config.

I don't think they are 'standard c' though ;)

OK, I'm just having a trudge through druntime: intptr_t and uintptr_t are guaranteed to match pointer size. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stdint.d#cl-70 c_long and c_ulong are guaranteed to match target long size (here would also go c_int and c_uint ;-). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22 This needs fixing, as wchar_t may not be same size across all targets (some change size of wchar_t based on compile time switches). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stddef.d#cl-28 This needs fixing, as wint_t may not be same size across all targets. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/wchar_.d#cl-29 -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';

It seems the problem is already MUCH worse than in D already :( .. this was precisely my fear. Why all these redundant aliases? Just for C compatibility? Exactly one identifier for each concept should be nominated and promoted as 'standard' in D, and everyone use that same thing... The myriad of aliases may still be useful for extern(C) I suppose, but I think this is a major problem that needs careful consideration. I think one of the most insidious side effects of this problem is that programmers don't fully understand what each type is meant to represent exactly, and they accidentally select the wrong one that just appears to do the job correctly on their machine/platform at that particular moment. I'm sure this is the reason behind C compilers messing up the definition of these themselves types so frequently. --00248c7117955c2b1a04b96a82f9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 19:21, Iain Buclaw <span dir= =3D"ltr">&lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw ubuntu.com</a>&g= t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0= .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 20 February 2012 16:20, Manu &lt= ;<a href=3D"mailto:turkeyman gmail.com">turkeyman gmail.com</a>&gt; wrote:<= br> &gt; On 20 February 2012 16:03, Iain Buclaw &lt;<a href=3D"mailto:ibuclaw u= buntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt;&gt;<br> &gt;&gt; On 20 February 2012 11:14, Manu &lt;<a href=3D"mailto:turkeyman gm= ail.com">turkeyman gmail.com</a>&gt; wrote:<br> &gt;&gt; &gt; On 20 February 2012 10:31, Iain Buclaw &lt;<a href=3D"mailto:= ibuclaw ubuntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; On 19 February 2012 18:27, Manu &lt;<a href=3D"mailto:tur= keyman gmail.com">turkeyman gmail.com</a>&gt; wrote:<br> &gt;&gt; &gt;&gt; &gt; On 19 February 2012 20:07, Timon Gehr &lt;<a href=3D= "mailto:timon.gehr gmx.ch">timon.gehr gmx.ch</a>&gt; wrote:<br> &gt;&gt; &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt; On 02/19/2012 03:59 PM, Manu wrote:<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; Okay, so it came up a couple of times, but t= he questions is, what<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; are<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; we<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; going to do about it?<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; size_t and ptrdiff_t are incomplete, and rep= resent<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; non-complimentary<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; signed/unsigned halves of the requirement.<b= r> &gt;&gt; &gt;&gt; &gt;&gt;&gt; There are TWO types needed, register size, a= nd pointer size.<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; Currently,<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; these are assumed to be the same, which is a= false assumption.<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; I propose size_t + ssize_t should both exist= , and represent the<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; native<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; integer size. Also something like ptr_t, and= ptrdiff_t should also<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; exist, and represent the size of the pointer= .<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; Personally, I don&#39;t like the _t notation= at all. It doesn&#39;t fit the<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; rest<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; of the D types, but it&#39;s established, so= I don&#39;t expect it can<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; change.<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; But we do need the 2 missing types.<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; There is also the problem that there is lots= of code written using<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; the<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; incorrect types. Some time needs to be taken= to correct phobos too<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; I<br> &gt;&gt; &gt;&gt; &gt;&gt;&gt; guess.<br> &gt;&gt; &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt; Currently, size_t is defined to be what you call= ptr_t, ptrdiff_t is<br> &gt;&gt; &gt;&gt; &gt;&gt; present, and what you call size_t/ssize_t does n= ot exist. Under<br> &gt;&gt; &gt;&gt; &gt;&gt; which<br> &gt;&gt; &gt;&gt; &gt;&gt; circumstances is it important to have a distinct= type that denotes<br> &gt;&gt; &gt;&gt; &gt;&gt; the<br> &gt;&gt; &gt;&gt; &gt;&gt; register size? What kind of code requires such a= type? It is<br> &gt;&gt; &gt;&gt; &gt;&gt; unportable.<br> &gt;&gt; &gt;&gt; &gt;<br> &gt;&gt; &gt;&gt; &gt;<br> &gt;&gt; &gt;&gt; &gt; It is just as unportable as size_t its self. The rea= son you need it<br> &gt;&gt; &gt;&gt; &gt; is<br> &gt;&gt; &gt;&gt; &gt; to<br> &gt;&gt; &gt;&gt; &gt; improve portability, otherwise people need to create= arbitrary<br> &gt;&gt; &gt;&gt; &gt; version<br> &gt;&gt; &gt;&gt; &gt; mess,<br> &gt;&gt; &gt;&gt; &gt; which will inevitably be incorrect.<br> &gt;&gt; &gt;&gt; &gt; Anything from calling convention code, structure lay= out/packing,<br> &gt;&gt; &gt;&gt; &gt; copying<br> &gt;&gt; &gt;&gt; &gt; memory, basically optimising for 64bits at all... I = can imagine<br> &gt;&gt; &gt;&gt; &gt; static<br> &gt;&gt; &gt;&gt; &gt; branches on the width of that type to select differe= nt paths.<br> &gt;&gt; &gt;&gt; &gt; Even just basic efficiency, using 32bit ints on many= 64bit machines<br> &gt;&gt; &gt;&gt; &gt; require<br> &gt;&gt; &gt;&gt; &gt; extra sign-extend opcodes after every single load...= total waste of<br> &gt;&gt; &gt;&gt; &gt; cpu<br> &gt;&gt; &gt;&gt; &gt; time.<br> &gt;&gt; &gt;&gt; &gt;<br> &gt;&gt; &gt;&gt; &gt; Currently, if you&#39;re running a 64bit system with= 32bit pointers,<br> &gt;&gt; &gt;&gt; &gt; there<br> &gt;&gt; &gt;&gt; &gt; is<br> &gt;&gt; &gt;&gt; &gt; absolutely nothing that exists at compile time to te= ll you you&#39;re<br> &gt;&gt; &gt;&gt; &gt; running a<br> &gt;&gt; &gt;&gt; &gt; 64bit system, or to declare a variable of the machin= es native type,<br> &gt;&gt; &gt;&gt; &gt; which<br> &gt;&gt; &gt;&gt; &gt; you&#39;re crazy if you say is not important informa= tion. What&#39;s the<br> &gt;&gt; &gt;&gt; &gt; point<br> &gt;&gt; &gt;&gt; &gt; of a<br> &gt;&gt; &gt;&gt; &gt; 64bit machine, if you treat it exactly like a 32bit = machine in every<br> &gt;&gt; &gt;&gt; &gt; aspect?<br> &gt;&gt; &gt;&gt;<br> &gt;&gt; &gt;&gt; gdc offers __builtin_machine_(u)int for word size, and<br=

s module.<br> &gt;&gt; &gt;&gt; Nevermind though, it&#39;s not quite a &quot;standard&quo= t; :~)<br> &gt;&gt; &gt;<br> &gt;&gt; &gt;<br> &gt;&gt; &gt; That&#39;s beautiful though! Can we alias them, and produce a= true D type<br> &gt;&gt; &gt; that<br> &gt;&gt; &gt; represents them? :)<br> &gt;&gt; &gt;<br> &gt;&gt; &gt; My basic issue with these size_t/c_int/core.stdc... stuff, is= that it<br> &gt;&gt; &gt; seems<br> &gt;&gt; &gt; the intent is to go out of the way to maintain compatibility = with C, at<br> &gt;&gt; &gt; the<br> &gt;&gt; &gt; expense of sucking C&#39;s messy and poorly defined types int= o D, which is a<br> &gt;&gt; &gt; shame. It just results in D having the same crappy archaic ty= ping<br> &gt;&gt; &gt; problems<br> &gt;&gt; &gt; as C.<br> &gt;&gt; &gt; I appreciate that the C types should exist for interoperabili= ty with C<br> &gt;&gt; &gt; (ie,<br> &gt;&gt; &gt; their quirks should be preserved for any given compiler/archi= tecture),<br> &gt;&gt; &gt; but<br> &gt;&gt; &gt; I&#39;d also like to see strictly defined types in D with no = respect to any<br> &gt;&gt; &gt; C<br> &gt;&gt; &gt; counterpart, guaranteed by the language to be exactly what th= ey claim to<br> &gt;&gt; &gt; be,<br> &gt;&gt; &gt; and not confused depending which compiler you try to use.<br> &gt;&gt; &gt;<br> &gt;&gt; &gt; These 2 GCC intrinsics would appear to be precisely what I wa= s looking<br> &gt;&gt; &gt; for<br> &gt;&gt; &gt; at the start of this thread...<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; Well, as Walter said, these could be aliased in core.stdc.config.<= br> &gt;<br> &gt;<br> &gt; I don&#39;t think they are &#39;standard c&#39; though ;)<br> <br> </div></div>OK, I&#39;m just having a trudge through druntime:<br> <br> intptr_t and uintptr_t are guaranteed to match pointer size.<br> <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/co= re/stdc/stdint.d#cl-70" target=3D"_blank">https://bitbucket.org/goshawk/gdc= /src/87241c8e754b/d/druntime/core/stdc/stdint.d#cl-70</a><br> <br> c_long and c_ulong are guaranteed to match target long size (here<br> would also go c_int and c_uint ;-).<br> <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/co= re/stdc/config.d#cl-22" target=3D"_blank">https://bitbucket.org/goshawk/gdc= /src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22</a><br> <br> This needs fixing, as wchar_t may not be same size across all targets<br> (some change size of wchar_t based on compile time switches).<br> <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/co= re/stdc/stddef.d#cl-28" target=3D"_blank">https://bitbucket.org/goshawk/gdc= /src/87241c8e754b/d/druntime/core/stdc/stddef.d#cl-28</a><br> <br> This needs fixing, as wint_t may not be same size across all targets.<br> <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/co= re/stdc/wchar_.d#cl-29" target=3D"_blank">https://bitbucket.org/goshawk/gdc= /src/87241c8e754b/d/druntime/core/stdc/wchar_.d#cl-29</a><br> <div class=3D"HOEnZb"><div class=3D"h5"><br> --<br> Iain Buclaw<br> <br> *(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;<br> </div></div></blockquote></div><br><div>It seems the problem is already MUC= H worse than in D already :( .. this was precisely my fear.</div><div>Why a= ll these redundant aliases? Just for C compatibility?</div><div><br></div> <div>Exactly one identifier for each concept should be nominated and promot= ed as &#39;standard&#39; in D, and everyone use that same thing...</div><di= v>The myriad of aliases may still be useful for extern(C) I suppose, but I = think this is a major problem that needs careful consideration.</div> <div><br></div><div>I think one of the most=C2=A0insidious=C2=A0side effect= s of this problem is that programmers don&#39;t fully understand what each = type is meant to represent exactly, and they accidentally select the wrong = one that just appears to do the job correctly on their machine/platform at = that particular moment. I&#39;m sure this is the reason behind C compilers = messing up the definition of these themselves types so frequently.</div> --00248c7117955c2b1a04b96a82f9--
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c768f9e295a9c04b96a9a53
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 20:07, Artur Skawina <art.08.09 gmail.com> wrote:

 On 02/20/12 13:32, Stewart Gordon wrote:
 On 20/02/2012 03:44, Artur Skawina wrote:
 <snip>
 Why would you want to do that, as opposed to use one of the pointer



 indeed required for GC to work correctly)?

That's how it can be used in *C*. And the reason it needs to be exposed to D code is for interoperability


 IINM, C calling conventions care only about the size of a type, not the

struct S { uintptr_t a; }; extern (C) uintptr_t f(S* s, uintptr_t* blah); "uintptr_t" is not the best example here (because it will rarely appear in C APIs), but still shows the problem - you need to know what it is - otherwise you're left with guessing and eg assuming that uintptr==size_t. Fixing historical mistakes can be hard. There are basically three types of integer types: a) known fixed size types, such as a 32-bit wide unsigned int b) types, that are not explicitly sized, but meet certain criteria, eg: sizeof(short)<=sizeof(int)<=sizeof(long) c) externally defined types, which must always have the same representation, the above uintptr_t example falls into this category. 'C' didn't have the (a) types, so everybody had to redefine u8/s16/u32/s64 etc. 'D' added these as builtin types so that problem was solved. Unfortunately, instead of eg using the de facto std s16/s32/s64, D reused short/int/long. 'C's short/int/long were poorly (too loosely) defined, but what should have been done is defining them in 'D' as, for example: int: efficient integer type, fitting in a CPU register and at least 32 bit wide;

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. 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)
 long: efficient integer type, fitting in a CPU register and as wide as a
 GPR.

I don't think the term 'long' here, as opposed to 'int' draws this distinction... so I really can't buy into this logic.
 Fixing things up now, with for example "nativeInt" (maps to "int" above)
 and
 "widestInt" (the "long" above), is not easy. They are needed, that's why
 threads like this one appear, but simply adding them to the language or std
 library [1] wouldn't be enough. Why? Think literals, promotion and auto --
 I'm afraid programmers working with 'native' ints may not be expecting
 expressions evaluating to a narrower type.

 So there probably is no ideal simple solution for D2. For 64-bit platforms
 and
 a future D3 language, the int/long, as defined above, would be a mostly
 backward
 compatible change.

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. People should only use these resizing types deliberately when they know what they're doing.
 artur

 [1] fundamental types like these should not require any imports, so
 object.d
    and/or compiler is the best place for them.

--00248c768f9e295a9c04b96a9a53 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 20:07, Artur Skawina <span d= ir=3D"ltr">&lt;<a href=3D"mailto:art.08.09 gmail.com">art.08.09 gmail.com</= a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0= 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 02/20/12 13:32, Stewart Gordon w= rote:<br> &gt; On 20/02/2012 03:44, Artur Skawina wrote:<br> &gt; &lt;snip&gt;<br> &gt;&gt;&gt; Why would you want to do that, as opposed to use one of the po= inter types (which is<br> &gt;&gt;&gt; indeed required for GC to work correctly)?<br> &gt;&gt;<br> &gt;&gt; That&#39;s how it can be used in *C*.<br> &gt;&gt;<br> &gt;&gt; And the reason it needs to be exposed to D code is for interoperab= ility with C.<br> &gt;<br> &gt; IINM, C calling conventions care only about the size of a type, not th= e name or intrinsic nature of it. =C2=A0Therefore 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> &quot;uintptr_t&quot; 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 - otherwis= e<br> you&#39;re left with guessing and eg assuming that uintptr=3D=3Dsize_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> =C2=A0 =C2=A0 eg: sizeof(short)&lt;=3Dsizeof(int)&lt;=3Dsizeof(long)<br> c) externally defined types, which must always have the same representation= ,<br> =C2=A0 =C2=A0the above uintptr_t example falls into this category.<br> <br> &#39;C&#39; didn&#39;t have the (a) types, so everybody had to redefine u8/= s16/u32/s64 etc.<br> &#39;D&#39; added these as builtin types so that problem was solved. Unfort= unately,<br> instead of eg using the de facto std s16/s32/s64, D reused short/int/long.<= br> &#39;C&#39;s short/int/long were poorly (too loosely) defined, but what sho= uld have<br> been done is defining them in &#39;D&#39; as, for example:<br> <br> int: =C2=A0efficient integer type, fitting in a CPU register and at least 3= 2 bit wide;<br></blockquote><div><br></div><div>No, this would be very very= bad. People would use &#39;int&#39; out of habit in data structures, and m= ess up binary compatibility and alignment rules.</div> <div>I personally quite like D&#39;s int types as they are, but note there = are some &#39;missing&#39; (well, not missing, as we&#39;re discussing, but= they are not well defined, or named, and needlessly aliased)</div><div> =C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo= rder-left:1px #ccc solid;padding-left:1ex"> long: efficient integer type, fitting in a CPU register and as wide as a GP= R.<br></blockquote><div><br></div><div>I don&#39;t think the term &#39;long= &#39; here, as opposed to &#39;int&#39; draws this distinction... so I real= ly can&#39;t buy into this logic.</div> <div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8= ex;border-left:1px #ccc solid;padding-left:1ex">Fixing things up now, with = for example &quot;nativeInt&quot; (maps to &quot;int&quot; above) and<br> &quot;widestInt&quot; (the &quot;long&quot; above), is not easy. They are n= eeded, that&#39;s why<br> threads like this one appear, but simply adding them to the language or std= <br> library [1] wouldn&#39;t be enough. Why? Think literals, promotion and auto= --<br> I&#39;m afraid programmers working with &#39;native&#39; ints may not be ex= pecting<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 bac= kward<br> compatible change.<br></blockquote><div><br></div><div>I prefer to explicit= ly identify these types personally. Predictable sized types are better to h= ave people punching away with no real consideration to the specific use cas= e.</div> <div>People should only use these resizing types deliberately when they kno= w what they&#39;re doing.</div><div>=C2=A0</div><blockquote class=3D"gmail_= quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1= ex">artur<br> <br> [1] fundamental types like these should not require any imports, so object.= d<br> =C2=A0 =C2=A0and/or compiler is the best place for them.<br> </blockquote></div><br> --00248c768f9e295a9c04b96a9a53--
Feb 20 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Feb 20, 2012, at 11:43 AM, Manu wrote:

 On 20 February 2012 19:21, Iain Buclaw <ibuclaw ubuntu.com> wrote:
=20
 OK, I'm just having a trudge through druntime:
=20
 intptr_t and uintptr_t are guaranteed to match pointer size.
 =

dint.d#cl-70
=20
 c_long and c_ulong are guaranteed to match target long size (here
 would also go c_int and c_uint ;-).
 =

nfig.d#cl-22
=20
 This needs fixing, as wchar_t may not be same size across all targets
 (some change size of wchar_t based on compile time switches).
 =

ddef.d#cl-28
=20
 This needs fixing, as wint_t may not be same size across all targets.
 =

har_.d#cl-29
=20
 --
 Iain Buclaw
=20
 *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
=20
 It seems the problem is already MUCH worse than in D already :( .. =

 Why all these redundant aliases? Just for C compatibility?

core.stdc is an interface to the C99 API, so everything is preserved = verbatim. c_long and c_ulong were added because the size of C long = differs between Windows and non-Windows x86_64 platforms. Typically, = int, short, etc are the same however, which is why there's currently no = c_int--it was just a needless complication at the time. The aliases for = D users, if the exist at all, should be separate.=
Feb 20 2012
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Mon, 20 Feb 2012 21:43:31 +0200
schrieb Manu <turkeyman gmail.com>:

 On 20 February 2012 19:21, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 
 On 20 February 2012 16:20, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 16:03, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 On 20 February 2012 11:14, Manu <turkeyman gmail.com> wrote:
 On 20 February 2012 10:31, Iain Buclaw <ibuclaw ubuntu.com>
 wrote:
 On 19 February 2012 18:27, Manu <turkeyman gmail.com> wrote:
 On 19 February 2012 20:07, Timon Gehr <timon.gehr gmx.ch>
 wrote:
 On 02/19/2012 03:59 PM, Manu wrote:
 Okay, so it came up a couple of times, but the questions
 is, what are
 we
 going to do about it?

 size_t and ptrdiff_t are incomplete, and represent
 non-complimentary
 signed/unsigned halves of the requirement.
 There are TWO types needed, register size, and pointer
 size. Currently,
 these are assumed to be the same, which is a false
 assumption.

 I propose size_t + ssize_t should both exist, and
 represent the native
 integer size. Also something like ptr_t, and ptrdiff_t
 should







 exist, and represent the size of the pointer.

 Personally, I don't like the _t notation at all. It
 doesn't fit







 rest
 of the D types, but it's established, so I don't expect
 it can change.
 But we do need the 2 missing types.

 There is also the problem that there is lots of code
 written







 the
 incorrect types. Some time needs to be taken to correct
 phobos







 I
 guess.

Currently, size_t is defined to be what you call ptr_t, ptrdiff_t






 present, and what you call size_t/ssize_t does not exist.
 Under which
 circumstances is it important to have a distinct type that
 denotes the
 register size? What kind of code requires such a type? It
 is unportable.

It is just as unportable as size_t its self. The reason you need it is to improve portability, otherwise people need to create arbitrary version mess, which will inevitably be incorrect. Anything from calling convention code, structure layout/packing, copying memory, basically optimising for 64bits at all... I can imagine static branches on the width of that type to select different paths. Even just basic efficiency, using 32bit ints on many 64bit machines require extra sign-extend opcodes after every single load... total waste of cpu time. Currently, if you're running a 64bit system with 32bit pointers, there is absolutely nothing that exists at compile time to tell you you're running a 64bit system, or to declare a variable of the machines native type, which you're crazy if you say is not important information. What's the point of a 64bit machine, if you treat it exactly like a 32bit machine in





 aspect?

gdc offers __builtin_machine_(u)int for word size, and __builtin_pointer_(u)int for pointer size via gcc.builtins module. Nevermind though, it's not quite a "standard" :~)

That's beautiful though! Can we alias them, and produce a true D type that represents them? :) My basic issue with these size_t/c_int/core.stdc... stuff, is that it seems the intent is to go out of the way to maintain compatibility with C,



 the
 expense of sucking C's messy and poorly defined types into D,
 which



 shame. It just results in D having the same crappy archaic
 typing problems
 as C.
 I appreciate that the C types should exist for
 interoperability with C (ie,
 their quirks should be preserved for any given
 compiler/architecture), but
 I'd also like to see strictly defined types in D with no
 respect to



 C
 counterpart, guaranteed by the language to be exactly what
 they claim



 be,
 and not confused depending which compiler you try to use.

 These 2 GCC intrinsics would appear to be precisely what I was
 looking for
 at the start of this thread...

Well, as Walter said, these could be aliased in core.stdc.config.

I don't think they are 'standard c' though ;)

OK, I'm just having a trudge through druntime: intptr_t and uintptr_t are guaranteed to match pointer size. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stdint.d#cl-70 c_long and c_ulong are guaranteed to match target long size (here would also go c_int and c_uint ;-). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22 This needs fixing, as wchar_t may not be same size across all targets (some change size of wchar_t based on compile time switches). https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/stddef.d#cl-28 This needs fixing, as wint_t may not be same size across all targets. https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/druntime/core/stdc/wchar_.d#cl-29 -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';

It seems the problem is already MUCH worse than in D already :( .. this was precisely my fear. Why all these redundant aliases? Just for C compatibility?

That's exactly what those types are for and that's the reason they're in core.stdc.* . Maybe those types shouldn't be used in normal D code, but they are necessary for C bindings.
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c71179530a2ab04b96ce662
Content-Type: text/plain; charset=UTF-8

On 20 February 2012 21:51, Sean Kelly <sean invisibleduck.org> wrote:

 On Feb 20, 2012, at 11:43 AM, Manu wrote:

 On 20 February 2012 19:21, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 OK, I'm just having a trudge through druntime:

 intptr_t and uintptr_t are guaranteed to match pointer size.

 c_long and c_ulong are guaranteed to match target long size (here
 would also go c_int and c_uint ;-).

 This needs fixing, as wchar_t may not be same size across all targets
 (some change size of wchar_t based on compile time switches).

 This needs fixing, as wint_t may not be same size across all targets.

 --
 Iain Buclaw

 *(p < e ? p++ : p) = (c & 0x0f) + '0';

 It seems the problem is already MUCH worse than in D already :( .. this

 Why all these redundant aliases? Just for C compatibility?

core.stdc is an interface to the C99 API, so everything is preserved verbatim. c_long and c_ulong were added because the size of C long differs between Windows and non-Windows x86_64 platforms. Typically, int, short, etc are the same however, which is why there's currently no c_int--it was just a needless complication at the time. The aliases for D users, if the exist at all, should be separate.

What about intptr_t/uintptr_t, are they builtins, or in core.stdc? --00248c71179530a2ab04b96ce662 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 20 February 2012 21:51, Sean Kelly <span dir= =3D"ltr">&lt;<a href=3D"mailto:sean invisibleduck.org">sean invisibleduck.o= rg</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg= in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On Feb 20, 2012, at 11:43 AM, Manu wrote:<br> <br> &gt; On 20 February 2012 19:21, Iain Buclaw &lt;<a href=3D"mailto:ibuclaw u= buntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt;<br> </div><div class=3D"im">&gt; OK, I&#39;m just having a trudge through drunt= ime:<br> &gt;<br> &gt; intptr_t and uintptr_t are guaranteed to match pointer size.<br> &gt; <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/drunti= me/core/stdc/stdint.d#cl-70" target=3D"_blank">https://bitbucket.org/goshaw= k/gdc/src/87241c8e754b/d/druntime/core/stdc/stdint.d#cl-70</a><br> &gt;<br> &gt; c_long and c_ulong are guaranteed to match target long size (here<br> &gt; would also go c_int and c_uint ;-).<br> &gt; <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/drunti= me/core/stdc/config.d#cl-22" target=3D"_blank">https://bitbucket.org/goshaw= k/gdc/src/87241c8e754b/d/druntime/core/stdc/config.d#cl-22</a><br> &gt;<br> &gt; This needs fixing, as wchar_t may not be same size across all targets<= br> &gt; (some change size of wchar_t based on compile time switches).<br> &gt; <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/drunti= me/core/stdc/stddef.d#cl-28" target=3D"_blank">https://bitbucket.org/goshaw= k/gdc/src/87241c8e754b/d/druntime/core/stdc/stddef.d#cl-28</a><br> &gt;<br> &gt; This needs fixing, as wint_t may not be same size across all targets.<= br> &gt; <a href=3D"https://bitbucket.org/goshawk/gdc/src/87241c8e754b/d/drunti= me/core/stdc/wchar_.d#cl-29" target=3D"_blank">https://bitbucket.org/goshaw= k/gdc/src/87241c8e754b/d/druntime/core/stdc/wchar_.d#cl-29</a><br> &gt;<br> &gt; --<br> &gt; Iain Buclaw<br> &gt;<br> &gt; *(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;<br> &gt;<br> &gt; It seems the problem is already MUCH worse than in D already :( .. thi= s was precisely my fear.<br> &gt; Why all these redundant aliases? Just for C compatibility?<br> <br> </div>core.stdc is an interface to the C99 API, so everything is preserved = verbatim. =C2=A0c_long and c_ulong were added because the size of C long di= ffers between Windows and non-Windows x86_64 platforms. =C2=A0Typically, in= t, short, etc are the same however, which is why there&#39;s currently no c= _int--it was just a needless complication at the time. =C2=A0The aliases fo= r D users, if the exist at all, should be separate.</blockquote> </div><br><div>What about intptr_t/uintptr_t, are they builtins, or in core= .stdc?</div> --00248c71179530a2ab04b96ce662--
Feb 20 2012
prev sibling next sibling parent Sean Kelly <sean invisibleduck.org> writes:
On Feb 20, 2012, at 2:34 PM, Manu wrote:
=20
 What about intptr_t/uintptr_t, are they builtins, or in core.stdc?

core.stdc. The only aliases that currently exist are defined in = object.di: alias typeof(int.sizeof) size_t; alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t; alias ptrdiff_t sizediff_t; We probably need to add ssize_t at some point. Not sure about anything = more than that.=
Feb 20 2012
prev sibling next sibling parent James Miller <james aatch.net> writes:
On 21 February 2012 12:22, Walter Bright <newshound2 digitalmars.com> wrote:
 On 2/20/2012 3:28 AM, Manu wrote:
 Even size_t is often
 broken in C. I have worked on 64bit systems with 32bit pointers where
 size_t was
 still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe
 my
 memory fails me)

I don't know how that could be considered C standard compliant.
 I want to be confident when I declare a numeric type that can interact
 with
 pointers, and also when I want the native type.

I think you're probably best off for now by doing your own alias for it.

I don't know much about what is considered 'standard C', non x86 platforms or the intricacies of native types, so I would like some clarification on the argument going on here. AFAICT, The problem is that size_t is assumed to be the both the size of the pointer and the size of the native int, but sometimes the native int isn't the same as the size of the pointer? So you can have 64bit native ints and 32bit pointers (and maybe even vice-versa)? I also saw reference to register sizes, which I assumed, but am now guessing to be wrong, were the same size as pointers. So the problem seems to be that there are the following things that are all different sizes: * fixed int (32 bit) * native int * pointer * register But some types are conflating them? The argument seems to be confusing me because it jumps rapidly from talking about different processors to different OSes to the C standard. If the only problem is that we need some more types, can't we add them in? I don't see the problem with having verbose, import-only names for things outside the norm, alias them if you want, longer names are better for newcomers. For example, what is ptrdiff_t? I have never seen that before, and the name doesn't help me, from the alias in druntime, it seems to be the type that represents the difference between 2 pointers. Help me out here, what on earth would I use that for? (On a side note to that, no way is ssize_t a good name, ever, forwards and backwards, what on earth is it? super-size_t? here to save you? shady-size_t? you have to make sure it doesn't sell you drugs? size-size_t? it has a stammer?) I also saw a lot of talk about C compilers that don't do the right thing, is that relevant? (I mean that sincerely, not criticism)
Feb 20 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c6a86e2bf2f9904b9754231
Content-Type: text/plain; charset=UTF-8

On 21 February 2012 01:22, Walter Bright <newshound2 digitalmars.com> wrote:

 On 2/20/2012 3:28 AM, Manu wrote:

 Even size_t is often
 broken in C. I have worked on 64bit systems with 32bit pointers where
 size_t was
 still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe
 my
 memory fails me)

I don't know how that could be considered C standard compliant.

I don't know about you, but I very rarely get to work with a C compiler that is 'standards compliant'.. that concept is kinda like a cruel joke in my experience. Does one even exist? :) I would like to have seen size_t and ptrdiff_t (and friends) also live in core.stdc... and D define and implement its own strictly compliant concepts. As is, any GDC build will have those types defined exactly as in the C compiler... broken or not, and since they're used to interact with C code, it can't be any other way. I want to be confident when I declare a numeric type that can interact with
 pointers, and also when I want the native type.

I think you're probably best off for now by doing your own alias for it.

Fair enough I guess. Consider it though. I really don't want to rely on core.stdc; that idea makes me feel very uneasy, considering how badly C stuffs all this stuff up. I also don't want to have to import something to access the most basic of types. --00248c6a86e2bf2f9904b9754231 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 21 February 2012 01:22, Walter Bright <span d= ir=3D"ltr">&lt;<a href=3D"mailto:newshound2 digitalmars.com">newshound2 dig= italmars.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" sty= le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 2/20/2012 3:28 AM, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Even size_t is often<br> broken in C. I have worked on 64bit systems with 32bit pointers where size_= t was<br> still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe m= y<br> memory fails me)<br> </blockquote> <br></div> I don&#39;t know how that could be considered C standard compliant.</blockq= uote><div><br></div><div>I don&#39;t know about you, but I very rarely get = to work with a C compiler that is &#39;standards compliant&#39;.. that conc= ept is kinda like a cruel joke in my experience. Does one even exist? :)</d= iv> <div>I would like to have seen size_t and ptrdiff_t (and friends) also live= in core.stdc... and D define and implement its own strictly compliant conc= epts. As is, any GDC build will have those types defined exactly as in the = C compiler... broken or not, and since they&#39;re used to interact with C = code, it can&#39;t be any other way.</div> <div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex= ;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"><blockquote= class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli= d;padding-left:1ex"> I want to be confident when I declare a numeric type that can interact with= <br> pointers, and also when I want the native type.<br> </blockquote> <br></div> I think you&#39;re probably best off for now by doing your own alias for it= .<br> </blockquote></div><br><div>Fair enough I guess. Consider it though. I real= ly don&#39;t want to rely on core.stdc; that idea makes me feel very uneasy= , considering how badly C stuffs all this stuff up.</div><div>I also don&#3= 9;t want to have to import something to access the most basic of types.</di= v> --00248c6a86e2bf2f9904b9754231--
Feb 21 2012
prev sibling next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Sunday, 19 February 2012 at 16:23:50 UTC, Manu wrote:
 On 19 February 2012 18:03, Vladimir Panteleev
 <vladimir thecybershadow.net>wrote:

 On Sunday, 19 February 2012 at 15:26:27 UTC, Manu wrote:

 There is code that assumes size_t is the width of the pointer

When is this not true? I can only think of 16-bit far pointers.


I know there are many systems with mismatching machine word and pointer size. I asked about cases where size_t.sizeof != (void*).sizeof.
Feb 21 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 21 February 2012 22:45, Juan Manuel Cabo <juanmanuel.cabo gmail.com> wrote:
 A REQUEST: how about adding a c_size_t too?

Eh? -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
Feb 21 2012
prev sibling next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, February 21, 2012 21:22:54 Walter Bright wrote:
 On 2/21/2012 4:50 PM, Juan Manuel Cabo wrote:
 Looking for size_t extravagancies in C, I found that VC uses __int64
 for size_t in x64 target.

Which is correct. size_t for 64 bit D is also a 64 bit integral type.

Yes, but __int64 is a signed integeral type, whereas size_t in D is an unsigned integeral type. - Jonathan M Davis
Feb 21 2012
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 22 February 2012 02:19, Walter Bright <newshound2 digitalmars.com> wrote=
:
 On 2/21/2012 1:03 AM, Artur Skawina wrote:
 Types like ptrdiff_t are not necessary in D, because you can write
 portable
 code using 'auto' and 'typeof()' - std C didn't have these, so a type ha=


 to be invented for everything.

And, in fact, object.di contains: alias typeof(int.sizeof) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0size_t; alias typeof(cast(void*)0 - cast(void*)0) =A0 ptrdiff_t;

But as far as I can see, size_t and ptrdiff_t have a special meaning inside the compiler, and you can change their alias at will (though I've never tried). --=20 Iain Buclaw *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
Feb 21 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00235447133472374c04b989881b
Content-Type: text/plain; charset=UTF-8

On 22 February 2012 03:31, Juan Manuel Cabo <juanmanuel.cabo gmail.com>wrote:

 On 02/21/2012 10:13 PM, Sean Kelly wrote:
 I think this is actually a good thing, since working with unsigned

Yes, I would prefer that msb bit to be the sign too, but behavior might depend on it, and correctness and predictability is important. My first code snippet was WRONG (sorry for the noise). And I couldn't even reproduce the problem with my VC. A correct snippet is simply this: size_t s = -2; if (s > 0) { printf("unsigned"); } else { printf("signed"); } Also, the shift operator is does a logical or arithmetic shift depending on whether it is signed or unsigned, so the result is different if you do s >> 1 whether s is signed or unsigned.

Actually, it doesn't. It is not defined by C whether it should be arithmetic or logical shift right, and it is up to the compiler to choose. Microsoft's PPC compiler produces a *logical* signed shift right for instance. --00235447133472374c04b989881b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 22 February 2012 03:31, Juan Manuel Cabo <spa= n dir=3D"ltr">&lt;<a href=3D"mailto:juanmanuel.cabo gmail.com">juanmanuel.c= abo gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" st= yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 02/21/2012 10:13 PM, Sean Kelly wrote:<br> &gt; I think this is actually a good thing, since working with unsigned int= egers is a pain.<br> <br> </div>Yes, I would prefer that msb bit to be the sign too, but behavior mig= ht depend on it,<br> and correctness and predictability is important.<br> <br> My first code snippet was WRONG (sorry for the noise). And I couldn&#39;t e= ven<br> reproduce the problem with my VC.<br> <br> A correct snippet is simply this:<br> <br> =C2=A0 =C2=A0size_t s =3D -2;<br> <br> =C2=A0 =C2=A0if (s &gt; 0) {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf(&quot;unsigned&quot;);<br> =C2=A0 =C2=A0} else {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf(&quot;signed&quot;);<br> =C2=A0 =C2=A0}<br> <br> Also, the shift operator is does a logical or arithmetic shift depending<br=

if you do<br> =C2=A0 =C2=A0 s &gt;&gt; 1<br> whether s is signed or unsigned.<br></blockquote><div><br></div><div>Actual= ly, it doesn&#39;t.</div><div>It is not defined by C whether it should be a= rithmetic or logical shift right, and it is up to the compiler to choose.</= div> <div>Microsoft&#39;s PPC compiler produces a *logical* signed shift right f= or instance.</div><div><br></div></div> --00235447133472374c04b989881b--
Feb 22 2012
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--00248c767e96901ecd04b98f6f7e
Content-Type: text/plain; charset=UTF-8

On 22 February 2012 17:16, Stewart Gordon <smjg_1998 yahoo.com> wrote:

 On 22/02/2012 07:24, Jacob Carlborg wrote:

 On 2012-02-22 06:24, Walter Bright wrote:

 On 2/21/2012 2:11 PM, Stewart Gordon wrote:


Are we going to have c_long_long as well?

Probably.

Wouldn't that always be a "long" in D? Or is it the same as with "long" in C.

long in D is 64 bits. long in C is 32 bits (on Win16/32 at least). If the C standard sets in stone the size of a long long, then we can do away with a c_long_long and just use long. Otherwise, if we're going to have c_int and c_long, it only makes sense to have c_long_long as well.

The C standard is completely irrelevant to D, and should not be considered. The C 'standard' is a guideline at best. I've worked with so many compilers over the years that fail, or ignore the standard in all kinds of ways. Their decisions towards the declaration of these fundamental types is a classic fuck up on lots of compilers. I can't trust anything in D defined to be "what c says".. if it's not defined and guaranteed by D, consider it as not-portable, and you'll probably need to start aliasing your own types inside super-portable libraries; version the hell out of it for every compiler you can find, just like C libs do. (Hello GLint (OpenGL), hkFloat(Havok), DWORD (windows), etc... can you think of a single super-portable library that DOESN'T redefine its primitive types?). As D cross compilers become more and more common, or other D compiler implementations begin to appear, the magnitude of the error will get more and more obvious, and also the longer it's left, the more impossible it will be to change. GDC takes its types from GCC verbatim, and they'll be every bit as broken as they would be in the corresponding C compiler. I just want D to define its types (including pointer (u)int, and native (u)int) explicitly in the D standard, and try and enforce it somehow to the tragedy never appears in D. --00248c767e96901ecd04b98f6f7e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 22 February 2012 17:16, Stewart Gordon <span = dir=3D"ltr">&lt;<a href=3D"mailto:smjg_1998 yahoo.com">smjg_1998 yahoo.com<= /a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:= 0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 22/02/2012 07:24, Jacob Carlborg wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 2012-02-22 06:24, Walter Bright wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 2/21/2012 2:11 PM, Stewart Gordon wrote:<br> </blockquote></blockquote></div> &lt;snip&gt;<div class=3D"im"><br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D"m= argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote c= lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;= padding-left:1ex"> Are we going to have c_long_long as well?<br> </blockquote> <br> Probably.<br> </blockquote> <br> Wouldn&#39;t that always be a &quot;long&quot; in D? Or is it the same as w= ith &quot;long&quot; in C.<br> </blockquote> <br></div> long in D is 64 bits.<br> long in C is 32 bits (on Win16/32 at least).<br> <br> If the C standard sets in stone the size of a long long, then we can do awa= y with a c_long_long and just use long. =C2=A0Otherwise, if we&#39;re going= to have c_int and c_long, it only makes sense to have c_long_long as well.= </blockquote> <div><br></div><div>The C standard is completely irrelevant to D, and shoul= d not be considered.</div><div>The C &#39;standard&#39; is a guideline at b= est. I&#39;ve worked with so many compilers over the years that fail, or ig= nore the standard in all kinds of ways.</div> <div>Their decisions towards the declaration of these fundamental types is = a classic fuck up on lots of compilers.</div><div>I can&#39;t trust anythin= g in D defined to be &quot;what c says&quot;.. if it&#39;s not defined and = guaranteed by D, consider it as not-portable, and you&#39;ll probably need = to start aliasing your own types inside super-portable libraries; version t= he hell out of it for every compiler you can find, just like C libs do. (He= llo GLint (OpenGL), hkFloat(Havok), DWORD (windows), etc... can you think o= f a single super-portable library that DOESN&#39;T redefine its primitive t= ypes?).</div> <div>As D cross compilers become more and more common, or other D compiler = implementations begin to appear, the magnitude of the error will get more a= nd more obvious, and also the longer it&#39;s left, the more impossible it = will be to change.</div> <div>GDC takes its types from GCC verbatim, and they&#39;ll be every bit as= broken as they would be in the corresponding C compiler.</div><div><br></d= iv><div>I just want D to define its types (including pointer (u)int, and na= tive (u)int) explicitly in the D standard, and try and enforce it somehow t= o the tragedy never appears in D.</div> </div> --00248c767e96901ecd04b98f6f7e--
Feb 22 2012
prev sibling parent Manu <turkeyman gmail.com> writes:
--002354530350681fb204b98f75fe
Content-Type: text/plain; charset=UTF-8

On 22 February 2012 17:39, Don Clugston <dac nospam.com> wrote:

 On 22/02/12 06:16, Walter Bright wrote:

 On 2/21/2012 6:07 PM, Juan Manuel Cabo wrote:

 16bit intel had 16bit segments and offsets, so memory was segmented
 and you couldn't address more than 64kb at a time.
 So you couldn't have grabbed^H^H"allocated" more than 64kb in real
 mode in intel
 in a single linear block.

size_t was 16 bits on all 16 bit memory models except the 'huge' one.

I expected that for ptrdiff_t, but for size_t as well? So sizeof(int *) was larger than size_t ?

I've worked on platforms where sizeof(void*) was smaller than sizeof(size_t) --002354530350681fb204b98f75fe Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div class=3D"gmail_quote">On 22 February 2012 17:39, Don Clugston <span di= r=3D"ltr">&lt;<a href=3D"mailto:dac nospam.com">dac nospam.com</a>&gt;</spa= n> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b= order-left:1px #ccc solid;padding-left:1ex"> <div class=3D"HOEnZb"><div class=3D"h5">On 22/02/12 06:16, Walter Bright wr= ote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On 2/21/2012 6:07 PM, Juan Manuel Cabo wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> 16bit intel had 16bit segments and offsets, so memory was segmented<br> and you couldn&#39;t address more than 64kb at a time.<br> So you couldn&#39;t have grabbed^H^H&quot;allocated&quot; more than 64kb in= real<br> mode in intel<br> in a single linear block.<br> </blockquote> <br> size_t was 16 bits on all 16 bit memory models except the &#39;huge&#39; on= e.<br> </blockquote> <br></div></div> I expected that for ptrdiff_t, but for size_t as well?<br> <br> So sizeof(int *) was larger than size_t ?<br></blockquote><div><br></div></= div>I&#39;ve worked on platforms where sizeof(void*) was smaller than sizeo= f(size_t) --002354530350681fb204b98f75fe--
Feb 22 2012