www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DMD32 vs DMD64 array.length

reply Andrea Fontana <advmail katamail.com> writes:
Some functions (for example array length) return ulong on dmd64 e uint
on dmd32=20
I need to compile on both platform: which is the right/best/clean way?
Nov 10 2011
next sibling parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
Andrea Fontana wrote:

 Some functions (for example array length) return ulong on dmd64 e uint
 on dmd32
 I need to compile on both platform: which is the right/best/clean way?
Andrea, use the size_t type.
Nov 10 2011
parent reply Andrea Fontana <advmail katamail.com> writes:
That's exactly what I was looking for. So it works as in most
programming languages :P=20
Dmd has deceived me. It says:

"Error: cannot implicitly convert expression (leaves.length) of type
ulong to uint"

It should say:
"Error: cannot implicitly convert expression (leaves.length) of type
size_t to uint"

Il giorno gio, 10/11/2011 alle 15.19 +0000, Dejan Lekic ha scritto:

 Andrea Fontana wrote:
=20
 Some functions (for example array length) return ulong on dmd64 e uint
 on dmd32
 I need to compile on both platform: which is the right/best/clean way?
=20 Andrea, use the size_t type.
Nov 11 2011
parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 11-11-2011 09:30, Andrea Fontana wrote:
 That's exactly what I was looking for. So it works as in most
 programming languages :P
 Dmd has deceived me. It says:

 "Error: cannot implicitly convert expression (leaves.length) of type
 ulong to uint"

 It should say:
 "Error: cannot implicitly convert expression (leaves.length) of type
 size_t to uint"

 Il giorno gio, 10/11/2011 alle 15.19 +0000, Dejan Lekic ha scritto:
 Andrea Fontana wrote:

  Some functions (for example array length) return ulong on dmd64 e uint
  on dmd32
  I need to compile on both platform: which is the right/best/clean way?
Andrea, use the size_t type.
DMD generally uses the actual type rather than the alias' name when you're using an aliased type. - Alex
Nov 11 2011
parent reply Andrea Fontana <advmail katamail.com> writes:
I don't think it's a good idea. In this case it's my fault, I should
imagine that a size_t datatype exists for arrays.
BTW on generic cases with aliases it would be useful to have an error
like :

"Error: cannot implicity convert expression (leaves.length) of type
size_t (ulong) to uint."

If not, i'll fix it using ulong and then when i'll go back on 32bit (or
on a case where alias is defined in another way) compiling will fail
again.

Il giorno ven, 11/11/2011 alle 09.58 +0100, Alex R=C3=B8nne Petersen ha
scritto:

 On 11-11-2011 09:30, Andrea Fontana wrote:
 That's exactly what I was looking for. So it works as in most
 programming languages :P
 Dmd has deceived me. It says:

 "Error: cannot implicitly convert expression (leaves.length) of type
 ulong to uint"

 It should say:
 "Error: cannot implicitly convert expression (leaves.length) of type
 size_t to uint"

 Il giorno gio, 10/11/2011 alle 15.19 +0000, Dejan Lekic ha scritto:
 Andrea Fontana wrote:

  Some functions (for example array length) return ulong on dmd64 e u=
int
  on dmd32
  I need to compile on both platform: which is the right/best/clean w=
ay?
 Andrea, use the size_t type.
=20 DMD generally uses the actual type rather than the alias' name when=20 you're using an aliased type. =20 - Alex
Nov 11 2011
next sibling parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 11-11-2011 10:13, Andrea Fontana wrote:
 I don't think it's a good idea. In this case it's my fault, I should
 imagine that a size_t datatype exists for arrays.
 BTW on generic cases with aliases it would be useful to have an error like :

 "Error: cannot implicity convert expression (leaves.length) of type
 size_t (ulong) to uint."

 If not, i'll fix it using ulong and then when i'll go back on 32bit (or
 on a case where alias is defined in another way) compiling will fail again.

 Il giorno ven, 11/11/2011 alle 09.58 +0100, Alex Rønne Petersen ha scritto:
 On 11-11-2011 09:30, Andrea Fontana wrote:
  That's exactly what I was looking for. So it works as in most
  programming languages :P
  Dmd has deceived me. It says:

  "Error: cannot implicitly convert expression (leaves.length) of type
  ulong to uint"

  It should say:
  "Error: cannot implicitly convert expression (leaves.length) of type
  size_t to uint"

  Il giorno gio, 10/11/2011 alle 15.19 +0000, Dejan Lekic ha scritto:
  Andrea Fontana wrote:

  >   Some functions (for example array length) return ulong on dmd64 e uint
  >   on dmd32
  >   I need to compile on both platform: which is the right/best/clean way?

  Andrea, use the size_t type.
DMD generally uses the actual type rather than the alias' name when you're using an aliased type. - Alex
I agree, that could be useful. Could you file a Bugzilla bug? - Alex
Nov 11 2011
parent bearophile <bearophileHUGS lycos.com> writes:
Alex R. Petersen:

 I agree, that could be useful. Could you file a Bugzilla bug?
See bug 5004. Bye, bearophile
Nov 11 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 11 Nov 2011 04:13:21 -0500, Andrea Fontana <advmail katamail.com>  
wrote:

 I don't think it's a good idea. In this case it's my fault, I should
 imagine that a size_t datatype exists for arrays.
size_t is not a builtin type. It's aliased to ulong or uint depending on the architecture. The compiler is not aware of size_t. However, given that the compiler has some quirky knowledge of phobos (i.e. if you use writeln without importing std.stdio, it gives you a helpful message about importing it), I would think we could do something along the same lines for array.length. -Steve
Nov 11 2011
prev sibling parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
On 10-11-2011 16:18, Andrea Fontana wrote:
 Some functions (for example array length) return ulong on dmd64 e uint
 on dmd32
 I need to compile on both platform: which is the right/best/clean way?
I don't understand what your actual question is, but size_t is what you should use for such things. (size_t == uint on x86, ulong on x86-64.) - Alex
Nov 10 2011