Jump to page: 1 214  
Page
Thread overview
Integer conversions too pedantic in 64-bit
Feb 14, 2011
dsimcha
Feb 14, 2011
Jonathan M Davis
Feb 15, 2011
Walter Bright
Feb 15, 2011
Andrej Mitrovic
Feb 15, 2011
Walter Bright
Feb 15, 2011
Andrej Mitrovic
Feb 15, 2011
Jonathan M Davis
Feb 15, 2011
spir
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
spir
Feb 15, 2011
Piotr Szturmaj
Feb 15, 2011
spir
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
spir
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
bearophile
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
spir
Feb 15, 2011
Adam Ruppe
Feb 15, 2011
Jens Mueller
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Piotr Szturmaj
Feb 15, 2011
Jacob Carlborg
Feb 15, 2011
Jonathan M Davis
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Don
Feb 15, 2011
spir
Feb 15, 2011
Jonathan M Davis
Feb 15, 2011
spir
Feb 15, 2011
Jonathan M Davis
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Jonathan M Davis
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Andrej Mitrovic
Feb 15, 2011
Walter Bright
Feb 15, 2011
spir
Feb 15, 2011
Walter Bright
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
Walter Bright
Feb 15, 2011
Michel Fortin
Feb 15, 2011
spir
Feb 16, 2011
Mafi
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
spir
Feb 15, 2011
spir
Feb 15, 2011
Walter Bright
Feb 15, 2011
spir
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
Adam Ruppe
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
spir
Feb 16, 2011
Nick Sabalausky
Feb 15, 2011
spir
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
Nick Sabalausky
Feb 15, 2011
Lutger Blijdestijn
Feb 16, 2011
gölgeliyele
Feb 16, 2011
gölgeliyele
Feb 16, 2011
Jonathan M Davis
Feb 16, 2011
Daniel Gibson
Feb 15, 2011
spir
Feb 15, 2011
spir
Feb 15, 2011
Iain Buclaw
Feb 15, 2011
Rainer Schuetze
Feb 15, 2011
Rainer Schuetze
Feb 15, 2011
Daniel Gibson
Feb 15, 2011
spir
Feb 15, 2011
Daniel Gibson
Feb 16, 2011
Jonathan M Davis
Feb 16, 2011
Walter Bright
Feb 16, 2011
Michel Fortin
Feb 16, 2011
Nick Sabalausky
Feb 16, 2011
gölgeliyele
Feb 16, 2011
spir
Feb 16, 2011
Iain Buclaw
Feb 16, 2011
KennyTM~
Feb 17, 2011
Nick Sabalausky
Feb 17, 2011
Dmitry Olshansky
Feb 17, 2011
Denis Koroskin
Feb 17, 2011
David Nadlinger
Feb 17, 2011
Don
Feb 17, 2011
Russel Winder
Feb 17, 2011
Don
Feb 17, 2011
Olivier Pisano
Feb 17, 2011
Walter Bright
Feb 18, 2011
Russel Winder
Feb 18, 2011
Walter Bright
Feb 18, 2011
Nick Sabalausky
Feb 18, 2011
Jonathan M Davis
Feb 19, 2011
Walter Bright
Feb 19, 2011
Jonathan M Davis
Feb 19, 2011
Walter Bright
Feb 19, 2011
Max Samukha
Feb 19, 2011
Don
Feb 19, 2011
Walter Bright
Feb 19, 2011
Russel Winder
Feb 19, 2011
Nick Sabalausky
Feb 19, 2011
Jeff Nowakowski
Feb 18, 2011
Jonathan M Davis
Feb 18, 2011
Nick Sabalausky
Feb 17, 2011
Nick Sabalausky
Feb 17, 2011
spir
Feb 17, 2011
Don
Feb 16, 2011
Bernard Helyer
Feb 16, 2011
spir
Feb 16, 2011
Don
Feb 16, 2011
spir
Feb 16, 2011
Walter Bright
Feb 16, 2011
Don
Feb 17, 2011
Walter Bright
Feb 17, 2011
dsimcha
Feb 17, 2011
Kagamin
Feb 17, 2011
Walter Bright
Feb 17, 2011
Andrej Mitrovic
Feb 17, 2011
Walter Bright
Feb 17, 2011
Andrej Mitrovic
Feb 17, 2011
Walter Bright
Feb 17, 2011
Nick Sabalausky
Feb 18, 2011
Walter Bright
Feb 18, 2011
Alexander Malakhov
Feb 17, 2011
Kevin Bealer
Feb 17, 2011
Daniel Gibson
Feb 17, 2011
Kevin Bealer
Feb 17, 2011
spir
February 14, 2011
Now that DMD has a 64-bit beta available, I'm working on getting a whole bunch of code to compile in 64 mode.  Frankly, the compiler is way too freakin' pedantic when it comes to implicit conversions (or lack thereof) of array.length.  99.999% of the time it's safe to assume an array is not going to be over 4 billion elements long.  I'd rather have a bug the 0.001% of the time than deal with the pedantic errors the rest of the time, because I think it would be less total time and effort invested.  To force me to either put casts in my code everywhere or change my entire codebase to use wider integers (with ripple effects just about everywhere) strikes me as purity winning out over practicality.
February 14, 2011
On Monday, February 14, 2011 15:22:38 dsimcha wrote:
> Now that DMD has a 64-bit beta available, I'm working on getting a whole bunch of code to compile in 64 mode.  Frankly, the compiler is way too freakin' pedantic when it comes to implicit conversions (or lack thereof) of array.length.  99.999% of the time it's safe to assume an array is not going to be over 4 billion elements long.  I'd rather have a bug the 0.001% of the time than deal with the pedantic errors the rest of the time, because I think it would be less total time and effort invested.  To force me to either put casts in my code everywhere or change my entire codebase to use wider integers (with ripple effects just about everywhere) strikes me as purity winning out over practicality.

I would have thought that you'd be using size_t when dealing with arrays, since that's what their length and indexing type is.

- Jonathan M Davis
February 15, 2011
dsimcha wrote:
> Now that DMD has a 64-bit beta available, I'm working on getting a whole bunch
> of code to compile in 64 mode.  Frankly, the compiler is way too freakin'
> pedantic when it comes to implicit conversions (or lack thereof) of
> array.length.  99.999% of the time it's safe to assume an array is not going
> to be over 4 billion elements long.  I'd rather have a bug the 0.001% of the
> time than deal with the pedantic errors the rest of the time, because I think
> it would be less total time and effort invested.  To force me to either put
> casts in my code everywhere or change my entire codebase to use wider integers
> (with ripple effects just about everywhere) strikes me as purity winning out
> over practicality.

We dealt with that in updating Phobos/Druntime to 64 bits. The end result was worth it (and yes, there would have been undiscovered bugs without those pedantic checks).

Most of the issues are solved if you use auto and foreach where possible, and size_t for the rest of the cases.
February 15, 2011
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?
February 15, 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.
February 15, 2011
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.

- Jonathan m Davis
February 15, 2011
auto, size_t, foreach & friends.

Once we get a stable 64bit compiler it's time to start advertising the portability of D apps across 32/64bit, methinks! ;)
February 15, 2011
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)

Denis
-- 
_________________
vita es estrany
spir.wikidot.com

February 15, 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
February 15, 2011
"spir" <denis.spir@gmail.com> wrote in message news:mailman.1648.1297732015.4748.digitalmars-d@puremagic.com...
> 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)
>

My bikeshed is painted "native" and "word" :)




« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11