Integer conversions too pedantic in 64-bit

Jonathan M Davis jmdavisProg at gmx.com
Mon Feb 14 17:28:07 PST 2011


On Monday, February 14, 2011 17:06:43 spir wrote:
> On 02/15/2011 01:56 AM, Jonathan M Davis wrote:
> > On Monday, February 14, 2011 16:30:09 Andrej Mitrovic wrote:
> >> Here's something I've noticed (x86 code):
> >> 
> >> void main()
> >> {
> >> 
> >>      ulong size = 2;
> >>      int[] arr = new int[](size);
> >> 
> >> }
> >> 
> >> This will error with:
> >> sizetTest.d(8): Error: cannot implicitly convert expression (size) of
> >> type ulong to uint
> >> 
> >> size_t is aliased to uint since I'm running 32bit.
> >> 
> >> I'm really not experienced at all with 64bit, so I don't know if it's
> >> good to use uint explicitly (my hunch is that it's not good). uint as
> >> the array size wouldn't even compile in 64bit, right?
> >> 
> >> If I'm correct, wouldn't it be better if the error showed that it
> >> expects size_t which might be aliased to whatever type for a
> >> particular machine?
> > 
> > Use size_t. It's the type which is used. It's aliased to whichever type
> > is appropriate for the architecture. On 32 bits, that would be a 32 bit
> > integer, so it's uint. On 64 bits, that would be a 64 bit integer, so
> > it's ulong.
> 
> Rename size-t, or rather introduce a meaningful standard alias? (would vote
> for Natural)

Why? size_t is what's used in C++. It's well known and what lots of programmers 
would expect What would you gain by renaming it?

- Jonathan M Davis


More information about the Digitalmars-d mailing list