Integer conversions too pedantic in 64-bit
Walter Bright
newshound2 at digitalmars.com
Mon Feb 14 16:54:37 PST 2011
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?
Use size_t for all array indices and sizes, and you'll be fine.
> 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?
The compiler doesn't actually know about size_t.
More information about the Digitalmars-d
mailing list