Re: Signed-unsigned comparisons in Phobos

2011-08-13 Thread Jacob Carlborg
On 2011-08-13 00:08, Walter Bright wrote: On 8/12/2011 11:32 AM, Jacob Carlborg wrote: On 2011-08-12 20:16, Walter Bright wrote: On 8/12/2011 8:52 AM, Jonathan M Davis wrote: it's a practice that many people don't seem to follow (in both C/C++ and D), since it's so natural to use int (or auto

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/13/2011 12:37 AM, Ellery Newcomer wrote: On 08/12/2011 04:06 PM, Don wrote: No, it was specifically disallowed. Version D 2.037 Dec 3, 2009 New/Changed Features No more comma operators allowed between [ ]. I think that was for type declarations, not index expressions. you can still do

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/12/2011 11:06 PM, Don wrote: Timon Gehr wrote: On 08/12/2011 09:32 PM, bearophile wrote: Timon Gehr: foreach_reverse(i;0..array.length) writeln(array[i]),i--; I'd like to statically forbid some more usages of the comma operator in D :-) Some of them are already forbidden compared to

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Simen Kjaeraas
On Fri, 12 Aug 2011 20:36:32 +0200, Jacob Carlborg wrote: On 2011-08-12 20:26, Simen Kjaeraas wrote: On Fri, 12 Aug 2011 19:19:09 +0200, Marco Leise wrote: This way it is actually fun to cripple the for loop, yay. Still if people started to argue that it is a bad idea to modify variables in

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Ellery Newcomer
On 08/12/2011 04:06 PM, Don wrote: No, it was specifically disallowed. Version D 2.037 Dec 3, 2009 New/Changed Features No more comma operators allowed between [ ]. I think that was for type declarations, not index expressions. you can still do this: import std.stdio; struct X{ void opI

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Walter Bright
On 8/12/2011 11:32 AM, Jacob Carlborg wrote: On 2011-08-12 20:16, Walter Bright wrote: On 8/12/2011 8:52 AM, Jonathan M Davis wrote: it's a practice that many people don't seem to follow (in both C/C++ and D), since it's so natural to use int (or auto in D), Back in the olden days of C, it wa

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Don
Timon Gehr wrote: On 08/12/2011 09:32 PM, bearophile wrote: Timon Gehr: foreach_reverse(i;0..array.length) writeln(array[i]),i--; I'd like to statically forbid some more usages of the comma operator in D :-) Some of them are already forbidden compared to C. This is valid C code: int main

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/12/2011 09:32 PM, bearophile wrote: Timon Gehr: foreach_reverse(i;0..array.length) writeln(array[i]),i--; I'd like to statically forbid some more usages of the comma operator in D :-) Some of them are already forbidden compared to C. This is valid C code: int main() { int array[5

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/12/2011 08:32 PM, Jacob Carlborg wrote: On 2011-08-12 20:16, Walter Bright wrote: On 8/12/2011 8:52 AM, Jonathan M Davis wrote: it's a practice that many people don't seem to follow (in both C/C++ and D), since it's so natural to use int (or auto in D), Back in the olden days of C, it w

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Don
Jonathan M Davis wrote: On Friday, August 12, 2011 12:39:01 Don wrote: kennytm wrote: Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compiler shut up". That's pretty impressive. In C++ I find that such messages

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread bearophile
Timon Gehr: > foreach_reverse(i;0..array.length) writeln(array[i]),i--; I'd like to statically forbid some more usages of the comma operator in D :-) Some of them are already forbidden compared to C. This is valid C code: int main() { int array[5]; int i = 1; int j = 2; array[i,

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Jacob Carlborg
On 2011-08-12 20:26, Simen Kjaeraas wrote: On Fri, 12 Aug 2011 19:19:09 +0200, Marco Leise wrote: This way it is actually fun to cripple the for loop, yay. Still if people started to argue that it is a bad idea to modify variables in the condition I'd silently agree. So a look at "foreach_rever

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Jacob Carlborg
On 2011-08-12 20:16, Walter Bright wrote: On 8/12/2011 8:52 AM, Jonathan M Davis wrote: it's a practice that many people don't seem to follow (in both C/C++ and D), since it's so natural to use int (or auto in D), Back in the olden days of C, it was "best practice" to use int as an index. Time

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Simen Kjaeraas
On Fri, 12 Aug 2011 19:19:09 +0200, Marco Leise wrote: Am 12.08.2011, 17:48 Uhr, schrieb Simen Kjaeraas : On Fri, 12 Aug 2011 14:55:26 +0200, Marco Leise wrote: Am 12.08.2011, 12:22 Uhr, schrieb kennytm : Don wrote: I've had a look at a dozen or so of these, and they were all real

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Walter Bright
On 8/12/2011 8:52 AM, Jonathan M Davis wrote: it's a practice that many people don't seem to follow (in both C/C++ and D), since it's so natural to use int (or auto in D), Back in the olden days of C, it was "best practice" to use int as an index. Times have changed, but old habits die hard.

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Marco Leise
Am 12.08.2011, 17:48 Uhr, schrieb Simen Kjaeraas : On Fri, 12 Aug 2011 14:55:26 +0200, Marco Leise wrote: Am 12.08.2011, 12:22 Uhr, schrieb kennytm : Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compile

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Jonathan M Davis
On Friday, August 12, 2011 12:39:01 Don wrote: > kennytm wrote: > > Don wrote: > >> I've had a look at a dozen or so of these, and they were all real. I > >> didn't see any which require a cast to "make the compiler shut up". > >> That's pretty impressive. In C++ I find that such messages are near

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Simen Kjaeraas
On Fri, 12 Aug 2011 14:55:26 +0200, Marco Leise wrote: Am 12.08.2011, 12:22 Uhr, schrieb kennytm : Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compiler shut up". That's pretty impressive. In C++ I find tha

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Marco Leise
Am 12.08.2011, 15:44 Uhr, schrieb Timon Gehr : On 08/12/2011 03:33 PM, Marco Leise wrote: Am 12.08.2011, 15:08 Uhr, schrieb bearophile : Marco Leise: Just remember that reverse loops are written like this: for (size_t i = x.length; i-- > 0; ) {...} Thankfully in D there is foreach_revers

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Marco Leise
Am 12.08.2011, 14:55 Uhr, schrieb Marco Leise : for (size_t i = x.length; i-- > 0; ) {...} Actually this is probably better: for (auto i = x.length; i > 0; ) { --i; ... }

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/12/2011 03:33 PM, Marco Leise wrote: Am 12.08.2011, 15:08 Uhr, schrieb bearophile : Marco Leise: Just remember that reverse loops are written like this: for (size_t i = x.length; i-- > 0; ) {...} Thankfully in D there is foreach_reverse :-) import std.stdio; void main() { auto arra

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Marco Leise
Am 12.08.2011, 15:08 Uhr, schrieb bearophile : Marco Leise: Just remember that reverse loops are written like this: for (size_t i = x.length; i-- > 0; ) {...} Thankfully in D there is foreach_reverse :-) import std.stdio; void main() { auto array = [10, 20, 30]; for (size_t i = a

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Jacob Carlborg
On 2011-08-12 14:55, Marco Leise wrote: Am 12.08.2011, 12:22 Uhr, schrieb kennytm : Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compiler shut up". That's pretty impressive. In C++ I find that such messages a

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Timon Gehr
On 08/12/2011 03:08 PM, bearophile wrote: Marco Leise: Just remember that reverse loops are written like this: for (size_t i = x.length; i--> 0; ) {...} Thankfully in D there is foreach_reverse :-) import std.stdio; void main() { auto array = [10, 20, 30]; for (size_t i = array

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread bearophile
Marco Leise: > Just remember that reverse loops are written like this: > > for (size_t i = x.length; i-- > 0; ) {...} Thankfully in D there is foreach_reverse :-) import std.stdio; void main() { auto array = [10, 20, 30]; for (size_t i = array.length; i-- > 0; ) writeln(i, " "

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Marco Leise
Am 12.08.2011, 12:22 Uhr, schrieb kennytm : Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compiler shut up". That's pretty impressive. In C++ I find that such messages are nearly always false positives. The on

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Don
kennytm wrote: Don wrote: I've had a look at a dozen or so of these, and they were all real. I didn't see any which require a cast to "make the compiler shut up". That's pretty impressive. In C++ I find that such messages are nearly always false positives. The one case where it's a bit annoyi

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread kennytm
Don wrote: > I've had a look at a dozen or so of these, and they were all real. I > didn't see any which require a cast to "make the compiler shut up". > That's pretty impressive. In C++ I find that such messages are nearly > always false positives. > > The one case where it's a bit annoying is

Re: Signed-unsigned comparisons in Phobos

2011-08-12 Thread Don
bearophile wrote: I have added this bit of code to my dmd, it gives warnings in cases of integral signed-unsigned comparisons: https://github.com/D-Programming-Language/dmd/pull/119 Then I have compiled Phobos (with unittests) with the -wi switch, this has generated some of those signed-unsign

Signed-unsigned comparisons in Phobos

2011-08-11 Thread bearophile
I have added this bit of code to my dmd, it gives warnings in cases of integral signed-unsigned comparisons: https://github.com/D-Programming-Language/dmd/pull/119 Then I have compiled Phobos (with unittests) with the -wi switch, this has generated some of those signed-unsigned warning messages,