Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-27 Thread Kagamin via Digitalmars-d
On Tuesday, 25 November 2014 at 22:56:50 UTC, Ola Fosheim Grøstad wrote: I personally would take the monotonic optimizations and rather have a separate bit-fidling type that provides a clean builtin swiss-army-knife toolset that gives close to direct access to the whole arsenal that the CPU

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-27 Thread via Digitalmars-d
On Thursday, 27 November 2014 at 08:31:24 UTC, Kagamin wrote: I don't think there's such clear separation that can be expressed in a type, it's more in used coding practices rather than type. You can't change coding practice by introducing a new type. You need to separate and define the old

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-27 Thread bearophile via Digitalmars-d
Kagamin: You can't change coding practice by introducing a new type. We can try to change coding practice introducing new types :-) Bye, bearophile

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-26 Thread Frank Like via Digitalmars-d
when I migrate dfl codes from x86 to 64 bit,modify the drawing.d ,find the 'offset' and 'index',point(x,y),rect(x,y),all be keep with the 'lengh's type, so I don't modify them to size_t,only cast(int)length to int,then it's easy to migrate dfl codes to 64 bit. Ok,then dfl can work on 64

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Don via Digitalmars-d
On Monday, 24 November 2014 at 21:34:19 UTC, Walter Bright wrote: On 11/24/2014 2:20 AM, Don wrote: I believe I do understand the problem. As a practical matter, overflow checks are not going to be added for performance reasons. The performance overhead would be practically zero. All we

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread via Digitalmars-d
On Tuesday, 25 November 2014 at 07:39:44 UTC, Don wrote: No, that is not overflow. That is a carry. Overflow is when the sign bit changes. I think this discussion will be less confusing with clearing up the terminology. An overflow condition happens when the representation cannot hold the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Kagamin via Digitalmars-d
On Monday, 24 November 2014 at 21:34:19 UTC, Walter Bright wrote: In exchange, 99% of uses of unsigned would disappear from D code, and with it, a whole category of bugs. You're not proposing changing size_t, so I believe this statement is incorrect. The idea is to make unsigned types

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Don via Digitalmars-d
On Monday, 24 November 2014 at 15:56:44 UTC, Andrei Alexandrescu wrote: On 11/24/14 4:54 AM, Don wrote: In D, 1u - 2u 0u. This is defined behaviour, not an overflow. I think I get what you mean, but overflow is also defined behavior (in D at least). -- Andrei Aargh! You're right. That's

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread bearophile via Digitalmars-d
Don: Aargh! You're right. That's new, and dreadful. It didn't used to be. The offending commit is alexrp 2012-05-15 15:37:24 which only provides an unsigned example. Why are defining behaviour that is always a bug? Java makes it defined, but it has to because it doesn't have

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Kagamin via Digitalmars-d
On Tuesday, 25 November 2014 at 11:43:01 UTC, Don wrote: Why are defining behaviour that is always a bug? Java makes it defined, but it has to because it doesn't have unsigned types. I think the intention probably was to improve on the C situation, where there is undefined behaviour that really

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread via Digitalmars-d
On Tuesday, 25 November 2014 at 13:52:32 UTC, Kagamin wrote: Overflow checking doesn't contradict to overflow being defined. The latter simply reflects how hardware works, nothing else. And hardware works that way, because that's a fast implementation of arithmetic for general case. So you

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Kagamin via Digitalmars-d
On Tuesday, 25 November 2014 at 14:30:36 UTC, Ola Fosheim Grøstad wrote: So you are basically saying that D does not provide modular arithmetic, but allows you to continue with the incorrect result of an overflow as a modulo representation? Correctness is an emergent property - when behavior

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread via Digitalmars-d
On Tuesday, 25 November 2014 at 15:42:13 UTC, Kagamin wrote: Correctness is an emergent property - when behavior matches expectation, so overflow has variable correctness in various parts of the code. I assume you are basically saying that Walter's view that matching C++ is more important

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread Kagamin via Digitalmars-d
On Tuesday, 25 November 2014 at 15:52:22 UTC, Ola Fosheim Grøstad wrote: I assume you are basically saying that Walter's view that matching C++ is more important than getting it right, because some people might expect C++ behaviour. Yet Ada chose a different path and is considered a better

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-25 Thread via Digitalmars-d
On Tuesday, 25 November 2014 at 18:24:29 UTC, Kagamin wrote: C++ legacy is huge especially in culture. That said, the true issue is in beliefs (which probably stem from 16-bit era). Can't judge Ada, have no experience with it, though examples of Java and .net show how marginal is importance of

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Don via Digitalmars-d
On Friday, 21 November 2014 at 20:17:12 UTC, Walter Bright wrote: On 11/21/2014 7:36 AM, Don wrote: On Friday, 21 November 2014 at 04:53:38 UTC, Walter Bright wrote: 0 crossing bugs tend to show up much sooner, and often immediately. You're missing the point here. The problem is that people

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Don via Digitalmars-d
On Friday, 21 November 2014 at 17:23:51 UTC, Marco Leise wrote: Am Thu, 20 Nov 2014 08:18:23 + schrieb Don x...@nospam.com: It's particularly challenging in D because of the widespread use of 'auto': auto x = foo(); auto y = bar(); auto z = baz(); if (x - y z) { ... } This might be a

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Don via Digitalmars-d
On Friday, 21 November 2014 at 08:46:20 UTC, Walter Bright wrote: On 11/21/2014 12:10 AM, bearophile wrote: Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems have gone away. I'm not pretending anything. I am asking in

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Andrei Alexandrescu via Digitalmars-d
On 11/24/14 2:20 AM, Don wrote: I am proposing that for .length returns a signed type, that for array slices is guaranteed to never be negative. Assuming you do make the case this change is an improvement, do you believe it's worth the breakage it would create? -- Andrei

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Andrei Alexandrescu via Digitalmars-d
On 11/24/14 4:54 AM, Don wrote: In D, 1u - 2u 0u. This is defined behaviour, not an overflow. I think I get what you mean, but overflow is also defined behavior (in D at least). -- Andrei

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread ketmar via Digitalmars-d
On Mon, 24 Nov 2014 12:54:58 + Don via Digitalmars-d digitalmars-d@puremagic.com wrote: In D, 1u - 2u 0u. This is defined behaviour, not an overflow. p.s. sorry, of course this is not and overflow. this is underflow. signature.asc Description: PGP signature

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread ketmar via Digitalmars-d
On Mon, 24 Nov 2014 12:54:58 + Don via Digitalmars-d digitalmars-d@puremagic.com wrote: In D, 1u - 2u 0u. This is defined behaviour, not an overflow. this *is* overflow. D just has overflow result defined. signature.asc Description: PGP signature

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread via Digitalmars-d
On Monday, 24 November 2014 at 16:00:53 UTC, ketmar via Digitalmars-d wrote: this *is* overflow. D just has overflow result defined. So it basically is and isn't modular arithmetic at the same time? I think Ada got this right by providing the ability to specify the modulo value, so you can

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Matthias Bentrup via Digitalmars-d
On Monday, 24 November 2014 at 16:45:35 UTC, Ola Fosheim Grøstad wrote: On Monday, 24 November 2014 at 16:00:53 UTC, ketmar via Digitalmars-d wrote: this *is* overflow. D just has overflow result defined. So it basically is and isn't modular arithmetic at the same time? Overflow is part of

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread via Digitalmars-d
On Monday, 24 November 2014 at 17:12:31 UTC, Matthias Bentrup wrote: Overflow is part of modular arithmetic. However, there is no signed and unsigned modular arithmetic, or, more precisely, they are the same. Would you say that a phase that goes from 0…2pi overflows? Does polar coordinates

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread via Digitalmars-d
On Monday, 24 November 2014 at 17:55:06 UTC, Ola Fosheim Grøstad wrote: I think the point with having compiler support is to retain most optimizations. The compiler select the most efficient representation based on the needed headroom and makes sure that overflow is recorded so that you can

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Matthias Bentrup via Digitalmars-d
On Monday, 24 November 2014 at 17:55:06 UTC, Ola Fosheim Grøstad wrote: On Monday, 24 November 2014 at 17:12:31 UTC, Matthias Bentrup wrote: Overflow is part of modular arithmetic. However, there is no signed and unsigned modular arithmetic, or, more precisely, they are the same. Would you

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread via Digitalmars-d
On Monday, 24 November 2014 at 19:06:35 UTC, Matthias Bentrup wrote: There is no right or wrong in Mathematics, only true and false. The result of modular addition with overflow is not wrong, it is just different than the result of integer addition. I think we are talking past each other. In

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Walter Bright via Digitalmars-d
On 11/24/2014 2:20 AM, Don wrote: I believe I do understand the problem. As a practical matter, overflow checks are not going to be added for performance reasons. The performance overhead would be practically zero. All we would need to do, is restrict array slices such that the length cannot

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread FrankLike via Digitalmars-d
On Monday, 24 November 2014 at 19:06:35 UTC, Matthias Bentrup wrote: Agreed, though I don't like the explosion of new operators. I'd prefer the C# syntax like check(expression), wrap(expression), saturate(expression). You maybe like this: ---small test

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-24 Thread Don via Digitalmars-d
On Monday, 24 November 2014 at 16:00:53 UTC, ketmar via Digitalmars-d wrote: On Mon, 24 Nov 2014 12:54:58 + Don via Digitalmars-d digitalmars-d@puremagic.com wrote: In D, 1u - 2u 0u. This is defined behaviour, not an overflow. this *is* overflow. D just has overflow result defined.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-23 Thread via Digitalmars-d
On Friday, 21 November 2014 at 16:12:19 UTC, Don wrote: It is not uint.max. It is natint.max. And yes, that's an overflow condition. Exactly the same as when you do int.max + int.max. This depends on how you look at it. From a formal perspective assume zero as the base, then a predecessor

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-22 Thread via Digitalmars-d
On Friday, 21 November 2014 at 21:44:25 UTC, Marco Leise wrote: Am Wed, 19 Nov 2014 18:20:24 + schrieb Marc Schütz schue...@gmx.net: I'd say length being unsigned is fine. The real mistake is that the difference between two unsigned values isn't signed, which would be the most correct

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-22 Thread ketmar via Digitalmars-d
On Sat, 22 Nov 2014 03:09:59 + deadalnix via Digitalmars-d digitalmars-d@puremagic.com wrote: On Friday, 21 November 2014 at 09:47:32 UTC, Stefan Koch wrote: On Friday, 21 November 2014 at 09:37:50 UTC, Walter Bright wrote: I thought everyone hated foreach_reverse! I dislike

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-22 Thread via Digitalmars-d
On Saturday, 22 November 2014 at 11:12:06 UTC, Marc Schütz wrote: I'd say that when two values are to be subtracted (signed or unsigned), and there's no knowledge about which one is larger, it's more useful to get a signed difference. This should be correct in most cases, because I believe it

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-22 Thread Nick Treleaven via Digitalmars-d
On 20/11/2014 08:02, Walter Bright wrote: On 11/19/2014 5:03 PM, H. S. Teoh via Digitalmars-d wrote: If this kind of unsafe mixing wasn't allowed, or required explict casts (to signify yes I know what I'm doing and I'm prepared to face the consequences), I suspect that bearophile would be much

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-22 Thread Marco Leise via Digitalmars-d
Am Fri, 21 Nov 2014 17:50:11 -0800 schrieb Andrei Alexandrescu seewebsiteforem...@erdani.org: I agree, though foreach (i; length.iota.retro) is no slouch either! -- Andrei Yes, no, well, it feels like too much science for a loop with a decrementing index instead of an incrementing, no matter

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
FrankLike wrote in message news:musbvhmuuhhvetovx...@forum.dlang.org... If you compile the dfl Library to 64 bit,you will find error: core.sys.windows.windows.WaitForMultipleObjects(uint nCount,void** lpHandles,) is not callable using argument types(ulong,void**,...) the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
H. S. Teoh via Digitalmars-d wrote in message news:mailman.2156.1416499421.9932.digitalmar...@puremagic.com... By that logic, using an int to represent an integer is also using the incorrect type, because a signed type is *also* subject to module 2^^n arithmetic -- just a different form of it

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread bearophile via Digitalmars-d
Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems have gone away. I'm not pretending anything. I am asking in practical programming what of the two solutions leads to leas problems/bugs. So far I've seen the unsigned solution

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
Walter Bright wrote in message news:m4mggi$e1h$1...@digitalmars.com... BTW, granted the 0x7FFF problems exhibit the bugs less often, but paradoxically this can make the bug worse, because then it only gets found much, much later in supposedly tested robust code. 0 crossing bugs tend to

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
Andrei Alexandrescu wrote in message news:m4l711$1t39$1...@digitalmars.com... The most difficult pattern that comes to mind is the long arrow operator seen in backward iteration: void fun(int[] a) { for (auto i = a.length; i -- 0; ) { // use i } } Over the years

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
bearophile wrote in message news:lkcltlokangpzzdzz...@forum.dlang.org... From my experience in coding in D they are far more unlikely than sign-related bugs of array lengths. Here's a simple program to calculate the relative size of two files, that will not work correctly with unsigned

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Walter Bright via Digitalmars-d
On 11/21/2014 12:10 AM, Daniel Murphy wrote: Walter Bright wrote in message news:m4mggi$e1h$1...@digitalmars.com... BTW, granted the 0x7FFF problems exhibit the bugs less often, but paradoxically this can make the bug worse, because then it only gets found much, much later in supposedly

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Walter Bright via Digitalmars-d
On 11/21/2014 12:31 AM, Daniel Murphy wrote: Here's a simple program to calculate the relative size of two files, that will not work correctly with unsigned lengths. module sizediff import std.file; import std.stdio; void main(string[] args) { assert(args.length == 3, Usage: sizediff

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Walter Bright via Digitalmars-d
On 11/21/2014 12:10 AM, bearophile wrote: Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems have gone away. I'm not pretending anything. I am asking in practical programming what of the two solutions leads to leas problems/bugs.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
Walter Bright wrote in message news:m4mu0q$sc5$1...@digitalmars.com... Zero, on the other hand, is usually quite near the typical array lengths and differences in lengths. That's true, that's why they are detected sooner, when it is less costly to fix them. It would be even less costly

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread bearophile via Digitalmars-d
Daniel Murphy: void fun(int[] a) { foreach_reverse(i, 0...a.length) { } } Better (it's a workaround for a D design flaw that we're unwilling to fix): foreach_reverse(immutable i, 0...a.length) Bye, bearophile

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
Walter Bright wrote in message news:m4mua1$shh$1...@digitalmars.com... Presumably read() will throw if the size is larger than it can handle. If it doesn't, this code is not buggy, but read() is. You're right, but that's really not the point.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Matthias Bentrup via Digitalmars-d
On Friday, 21 November 2014 at 08:54:40 UTC, Daniel Murphy wrote: Walter Bright wrote in message news:m4mu0q$sc5$1...@digitalmars.com... Zero, on the other hand, is usually quite near the typical array lengths and differences in lengths. That's true, that's why they are detected sooner,

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Frank Like via Digitalmars-d
Here's a simple program to calculate the relative size of two files, that will not work correctly with unsigned lengths. module sizediff; import std.file; import std.stdio; void main(string[] args) { assert(args.length == 3, Usage: sizediff file1 file2); auto l1 = args[1].read().length;

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Kagamin via Digitalmars-d
On Friday, 21 November 2014 at 04:53:38 UTC, Walter Bright wrote: BTW, granted the 0x7FFF problems exhibit the bugs less often, but paradoxically this can make the bug worse, because then it only gets found much, much later in supposedly tested robust code. 0 crossing bugs tend to show

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Kagamin via Digitalmars-d
On Thursday, 20 November 2014 at 21:27:11 UTC, Walter Bright wrote: If that is changed to a signed type, then you'll have a same-only-different set of subtle bugs If people use signed length with unsigned integers, the length with implicitly convert to unsigned and behave like now, no

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Frank Like via Digitalmars-d
Mathematical difference between unsigned value,size comparison should be done before in the right side of the equal sign character. such as: l3 = (l1 l2)? (l1 - l2):(l2 - l1); If this work is done in druntime,small bug will be rarely.D will be a real system language. Frank

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Kagamin via Digitalmars-d
On Thursday, 20 November 2014 at 16:03:41 UTC, H. S. Teoh via Digitalmars-d wrote: By that logic, using an int to represent an integer is also using the incorrect type, because a signed type is *also* subject to module 2^^n arithmetic -- just a different form of it where the most negative

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Walter Bright via Digitalmars-d
On 11/21/2014 12:16 AM, Daniel Murphy wrote: Over the years most of my unsigned-related bugs have been from screwing up various loop conditions. Thankfully D solves this perfectly with: void fun(int[] a) { foreach_reverse(i, 0...a.length) { } } So I never have to write those

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Walter Bright via Digitalmars-d
On 11/21/2014 1:01 AM, Matthias Bentrup wrote: C# has the checked and unchecked operators (http://msdn.microsoft.com/en-us/library/khy08726.aspx), which allow the programmer to specify if overflows should wrap of fail within an arithmetic expression. That could be a useful addition to D. D

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Kagamin via Digitalmars-d
On Thursday, 20 November 2014 at 16:34:12 UTC, flamencofantasy wrote: My experience is totally the opposite of his. I have been using unsigned for lengths, widths, heights for the past 15 years in C, C++, C# and more recently in D with great success. I don't pretend to be any kind of authority

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Stefan Koch via Digitalmars-d
On Friday, 21 November 2014 at 09:37:50 UTC, Walter Bright wrote: I thought everyone hated foreach_reverse! I dislike foreach_reverse; 1. it's a keyword with an underscore in it; 2. complicates implementation of foreach and parsing. 3. key_word with under_score

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
bearophile wrote in message news:rqyuiioyrrjgggctf...@forum.dlang.org... Better (it's a workaround for a D design flaw that we're unwilling to fix): foreach_reverse(immutable i, 0...a.length) I know you feel that way, but I'd rather face the non-existent risk of accidentally mutating the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
On Friday, 21 November 2014 at 09:37:50 UTC, Walter Bright wrote: I thought everyone hated foreach_reverse! Not me. It's ugly but it gets the job done. All I have to do is add '_reverse' and it just works! Stefan Koch wrote in message news:mmvuvkdfnvwezyvtc...@forum.dlang.org... I

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Daniel Murphy via Digitalmars-d
Frank Like wrote in message news:zhejapfebcvxnzrez...@forum.dlang.org... If this work is done in druntime,D will be a real system language. Sure, this is obviously the fundamental thing holding D back from being a _real_ system language.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread bearophile via Digitalmars-d
Walter Bright: I thought everyone hated foreach_reverse! I love it! Bye, bearophile

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread bearophile via Digitalmars-d
Daniel Murphy: foreach_reverse(immutable i, 0...a.length) I know you feel that way, but I'd rather face the non-existent risk of accidentally mutating the induction variable than write immutable every time. It's not non-existent :-) (And the right default for a modern language is to

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread FrankLike via Digitalmars-d
On Friday, 21 November 2014 at 09:43:04 UTC, Kagamin wrote: On Thursday, 20 November 2014 at 16:34:12 UTC, flamencofantasy C# doesn't encourage usage of unsigned types and warns that they are not CLS-compliant. You're going against established practices there. And signed types for numbers

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread FrankLike via Digitalmars-d
Druntime's checkint.d should be modify: uint subu(uint x, uint y, ref bool overflow) { if (x y) return y - x; else return x - y; } uint subu(ulong x, ulong y, ref bool overflow) { if (x y) return y - x; else return x - y; } Frank

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread FrankLike via Digitalmars-d
D already has them: https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d Druntime's checkint.d should be modify: uint subu(uint x, uint y, ref bool overflow) { if (x y) return y - x; else return x - y; } ulong subu(ulong x, ulong y,

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread flamencofantasy via Digitalmars-d
On Friday, 21 November 2014 at 09:43:04 UTC, Kagamin wrote: C# doesn't encourage usage of unsigned types and warns that they are not CLS-compliant. You're going against established practices there. And signed types for numbers works wonders in C# without any notable problem and makes

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Thu, 20 Nov 2014 15:40:39 + Araq via Digitalmars-d digitalmars-d@puremagic.com wrote: Here are some more opinions: http://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here/ trying to illustrate something with obviously wrong code is very funny. the whole article then

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 08:10:55 + bearophile via Digitalmars-d digitalmars-d@puremagic.com wrote: BTW, granted the 0x7FFF problems exhibit the bugs less often, but paradoxically this can make the bug worse, because then it only gets found much, much later in supposedly tested

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 09:23:01 + Kagamin via Digitalmars-d digitalmars-d@puremagic.com wrote: C/C++ programmers disagree: http://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here/ Why do you think they can't handle signed integers? being C programmer i disagree that author

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Thu, 20 Nov 2014 13:28:37 -0800 Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 11/20/2014 7:52 AM, H. S. Teoh via Digitalmars-d wrote: What *could* be improved, is the prevention of obvious mistakes in *mixing* signed and unsigned types. Right now, D allows code

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Ary Borenszweig via Digitalmars-d
On 11/21/14, 5:45 AM, Walter Bright wrote: On 11/21/2014 12:10 AM, bearophile wrote: Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems have gone away. I'm not pretending anything. I am asking in practical programming what of

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 19:31:23 +1100 Daniel Murphy via Digitalmars-d digitalmars-d@puremagic.com wrote: bearophile wrote in message news:lkcltlokangpzzdzz...@forum.dlang.org... From my experience in coding in D they are far more unlikely than sign-related bugs of array lengths. Here's a

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Araq via Digitalmars-d
no, the problem 2 just becomes hidden. while the given code works most of the time, it is still broken. You cannot handle stack overflow in C reliably or out of memory conditions so fails in extreme edge cases is true for every piece of software. broken is not a black-white thing. Works most

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 11:17:06 -0300 Ary Borenszweig via Digitalmars-d digitalmars-d@puremagic.com wrote: This bug can manifest itself for arrays whose length (in elements) is 2^30 or greater (roughly a billion elements) How often does that happen in practice? once in almost ten years is too

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 14:37:39 + Araq via Digitalmars-d digitalmars-d@puremagic.com wrote: broken is not a black-white thing. Works most of the time surely is much more useful than doesn't work. Otherwise you would throw away your phone the first time you get a busy signal. works most of the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread FrankLike via Digitalmars-d
On Friday, 21 November 2014 at 13:59:08 UTC, ketmar via Digitalmars-d wrote: any code which does something like `if (a-b 0)` is broken. it Modify it: https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d Modify method: subu(uint ...) or subu(ulong ...)

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 14:55:45 + FrankLike via Digitalmars-d digitalmars-d@puremagic.com wrote: On Friday, 21 November 2014 at 13:59:08 UTC, ketmar via Digitalmars-d wrote: any code which does something like `if (a-b 0)` is broken. it Modify it:

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread FrankLike via Digitalmars-d
On Friday, 21 November 2014 at 15:13:22 UTC, ketmar via Digitalmars-d wrote: and it will not do the same anymore too. it's not a fix at all. But it is a part of bugs. Sure,bug which is in mixing sign and unsign values should be fix.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Don via Digitalmars-d
On Friday, 21 November 2014 at 04:53:38 UTC, Walter Bright wrote: On 11/20/2014 7:11 PM, Walter Bright wrote: On 11/20/2014 3:25 PM, bearophile wrote: Walter Bright: If that is changed to a signed type, then you'll have a same-only-different set of subtle bugs, This is possible. Can you

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread H. S. Teoh via Digitalmars-d
On Fri, Nov 21, 2014 at 03:36:01PM +, Don via Digitalmars-d wrote: [...] Suppose D had a type 'natint', which could hold natural numbers in the range 0..uint.max. Sounds like 'uint', right? People make the mistake of thinking that is what uint is. But it is not. How would natint

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Matthias Bentrup via Digitalmars-d
On Friday, 21 November 2014 at 15:36:02 UTC, Don wrote: On Friday, 21 November 2014 at 04:53:38 UTC, Walter Bright wrote: On 11/20/2014 7:11 PM, Walter Bright wrote: On 11/20/2014 3:25 PM, bearophile wrote: Walter Bright: If that is changed to a signed type, then you'll have a

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Andrei Alexandrescu via Digitalmars-d
On 11/21/14 12:56 AM, Daniel Murphy wrote: Walter Bright wrote in message news:m4mua1$shh$1...@digitalmars.com... Presumably read() will throw if the size is larger than it can handle. If it doesn't, this code is not buggy, but read() is. You're right, but that's really not the point.

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Don via Digitalmars-d
On Friday, 21 November 2014 at 15:50:05 UTC, H. S. Teoh via Digitalmars-d wrote: On Fri, Nov 21, 2014 at 03:36:01PM +, Don via Digitalmars-d wrote: [...] Suppose D had a type 'natint', which could hold natural numbers in the range 0..uint.max. Sounds like 'uint', right? People make the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Andrei Alexandrescu via Digitalmars-d
On 11/21/14 6:03 AM, ketmar via Digitalmars-d wrote: On Thu, 20 Nov 2014 13:28:37 -0800 Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 11/20/2014 7:52 AM, H. S. Teoh via Digitalmars-d wrote: What *could* be improved, is the prevention of obvious mistakes in *mixing*

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Wyatt via Digitalmars-d
On Thursday, 20 November 2014 at 20:17:15 UTC, deadalnix wrote: On Thursday, 20 November 2014 at 15:55:21 UTC, H. S. Teoh via Digitalmars-d wrote: Using unsigned types for array length doesn't necessarily lead to subtle bugs, if the language was stricter about mixing signed and unsigned

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Andrei Alexandrescu via Digitalmars-d
On 11/21/14 6:17 AM, Ary Borenszweig wrote: On 11/21/14, 5:45 AM, Walter Bright wrote: On 11/21/2014 12:10 AM, bearophile wrote: Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems have gone away. I'm not pretending anything. I

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread CraigDillabaugh via Digitalmars-d
On Thursday, 20 November 2014 at 08:14:41 UTC, Walter Bright wrote: clip For example, in America we drive on the right. In Australia, they drive on the left. When I visit Australia, I know this, but when stepping out into the road I instinctively check my left for cars, step into the road,

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 08:31:13 -0800 Andrei Alexandrescu via Digitalmars-d digitalmars-d@puremagic.com wrote: Would you agree that that would break a substantial amount of correct D code? -- Andrei i don't think that code with possible int wrapping and `auto` is correct, so the answer is no. bad

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Meta via Digitalmars-d
On Friday, 21 November 2014 at 16:48:35 UTC, CraigDillabaugh wrote: I live in Quebec and my intuition always tells me to look both ways - because you never know :o) While doing my driver's training years ago, my instructor half-jokingly warned us never to jaywalk in Quebec unless we have a

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Marco Leise via Digitalmars-d
Am Wed, 19 Nov 2014 10:22:49 + schrieb Dominikus Dittes Scherkl dominikus.sche...@continental-corporation.com: On Wednesday, 19 November 2014 at 09:06:16 UTC, Maroc Leise wrote: Clearly size_t (which I tend to alias with ℕ in my code for brevity and coolness) No, this is far from the

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread H. S. Teoh via Digitalmars-d
On Fri, Nov 21, 2014 at 08:31:13AM -0800, Andrei Alexandrescu via Digitalmars-d wrote: On 11/21/14 6:03 AM, ketmar via Digitalmars-d wrote: On Thu, 20 Nov 2014 13:28:37 -0800 Walter Bright via Digitalmars-d digitalmars-d@puremagic.com wrote: On 11/20/2014 7:52 AM, H. S. Teoh via

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Marco Leise via Digitalmars-d
Am Thu, 20 Nov 2014 08:18:23 + schrieb Don x...@nospam.com: It's particularly challenging in D because of the widespread use of 'auto': auto x = foo(); auto y = bar(); auto z = baz(); if (x - y z) { ... } This might be a bug, if one of these functions returns an unsigned

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Ary Borenszweig via Digitalmars-d
On 11/21/14, 11:29 AM, ketmar via Digitalmars-d wrote: On Fri, 21 Nov 2014 19:31:23 +1100 Daniel Murphy via Digitalmars-d digitalmars-d@puremagic.com wrote: bearophile wrote in message news:lkcltlokangpzzdzz...@forum.dlang.org... From my experience in coding in D they are far more unlikely

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Ary Borenszweig via Digitalmars-d
On 11/21/14, 11:47 AM, ketmar via Digitalmars-d wrote: On Fri, 21 Nov 2014 11:17:06 -0300 Ary Borenszweig via Digitalmars-d digitalmars-d@puremagic.com wrote: This bug can manifest itself for arrays whose length (in elements) is 2^30 or greater (roughly a billion elements) How often does that

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Ary Borenszweig via Digitalmars-d
On 11/21/14, 1:32 PM, Andrei Alexandrescu wrote: On 11/21/14 6:17 AM, Ary Borenszweig wrote: On 11/21/14, 5:45 AM, Walter Bright wrote: On 11/21/2014 12:10 AM, bearophile wrote: Walter Bright: All you're doing is trading 0 crossing for 0x7FFF crossing issues, and pretending the problems

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Marco Leise via Digitalmars-d
Am Fri, 21 Nov 2014 16:32:20 + schrieb Wyatt wyatt@gmail.com: Array lengths are always non-negative integers. This is axiomatic. But the subtraction thing keeps coming up in this thread; what to do? There's probably something fundamentally wrong with this and I'll probably be

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread Marco Leise via Digitalmars-d
Am Thu, 20 Nov 2014 20:53:31 -0800 schrieb Walter Bright newshou...@digitalmars.com: On 11/20/2014 7:11 PM, Walter Bright wrote: On 11/20/2014 3:25 PM, bearophile wrote: Walter Bright: If that is changed to a signed type, then you'll have a same-only-different set of subtle bugs,

Re: 'int' is enough for 'length' to migrate code from x86 to x64

2014-11-21 Thread ketmar via Digitalmars-d
On Fri, 21 Nov 2014 14:38:26 -0300 Ary Borenszweig via Digitalmars-d digitalmars-d@puremagic.com wrote: You see, if you don't use a BigNum for everything than you will always have hidden bugs, be it with int, uint or whatever. why do you believe that i'm not aware of overflows and don't

  1   2   3   >