Re: null Vs [] return arrays

2011-04-07 Thread Regan Heath
On Tue, 05 Apr 2011 18:46:06 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Tue, 05 Apr 2011 13:24:49 -0400, Regan Heath re...@netmail.co.nz wrote: On Fri, 01 Apr 2011 18:23:28 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: assert( !is null); // works on D. Try it.

Re: null Vs [] return arrays

2011-04-07 Thread Kagamin
bearophile Wrote: Regan Heath: conceptually it's nice to be able to express (exists but is empty) and (does not exist). You may want to express that, but for the implementation of the language those two situations are the same, because in the [] literal the ptr is null. So I think

Re: null Vs [] return arrays

2011-04-01 Thread Regan Heath
On Mon, 28 Mar 2011 17:54:29 +0100, bearophile bearophileh...@lycps.com wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This may be slightly OT but I just wanted to raise

Re: null Vs [] return arrays

2011-04-01 Thread bearophile
Regan Heath: conceptually it's nice to be able to express (exists but is empty) and (does not exist). You may want to express that, but for the implementation of the language those two situations are the same, because in the [] literal the ptr is null. So I think it's better for the

Re: null Vs [] return arrays

2011-04-01 Thread Torarin
2011/4/1 Regan Heath re...@netmail.co.nz: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile bearophileh...@lycps.com wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This

Re: null Vs [] return arrays

2011-04-01 Thread spir
On 04/01/2011 12:38 PM, Regan Heath wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile bearophileh...@lycps.com wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This

Re: null Vs [] return arrays

2011-04-01 Thread Steven Schveighoffer
On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath re...@netmail.co.nz wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile bearophileh...@lycps.com wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you

Re: null Vs [] return arrays

2011-04-01 Thread Regan Heath
On Fri, 01 Apr 2011 13:38:45 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath re...@netmail.co.nz wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile bearophileh...@lycps.com wrote: Steven Schveighoffer: So essentially, you are

Re: null Vs [] return arrays

2011-04-01 Thread Steven Schveighoffer
On Fri, 01 Apr 2011 11:52:47 -0400, Regan Heath re...@netmail.co.nz wrote: On Fri, 01 Apr 2011 13:38:45 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath re...@netmail.co.nz wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile

Re: null Vs [] return arrays

2011-03-28 Thread Kagamin
bearophile Wrote: Kagamin: [] is not null, it's an array of 0 elements, what is done exactly. edx points to the allocated array. I don't understand what you say. I think the caller of foo() and bar() receive the same thing, two empty registers. I think that cast(int[])null and

Re: null Vs [] return arrays

2011-03-28 Thread Steven Schveighoffer
On Sun, 27 Mar 2011 09:37:47 -0400, bearophile bearophileh...@lycos.com wrote: I have compiled this little D2 program: int[] foo() { return []; } int[] bar() { return null; } void main() {} Using DMD 2.052, dmd -O -release -inline test2.d This is the asm of the two functions:

Re: null Vs [] return arrays

2011-03-28 Thread bearophile
Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. Bye, bearophile

null Vs [] return arrays

2011-03-27 Thread bearophile
I have compiled this little D2 program: int[] foo() { return []; } int[] bar() { return null; } void main() {} Using DMD 2.052, dmd -O -release -inline test2.d This is the asm of the two functions: _D5test23fooFZAicomdat L0: pushEAX mov EAX,offset

Re: null Vs [] return arrays

2011-03-27 Thread Kagamin
bearophile Wrote: I have compiled this little D2 program: int[] foo() { return []; } int[] bar() { return null; } void main() {} Using DMD 2.052, dmd -O -release -inline test2.d This is the asm of the two functions: _D5test23fooFZAicomdat L0: pushEAX

Re: null Vs [] return arrays

2011-03-27 Thread bearophile
Kagamin: [] is not null, it's an array of 0 elements, what is done exactly. edx points to the allocated array. I don't understand what you say. I think the caller of foo() and bar() receive the same thing, two empty registers. I think that cast(int[])null and cast(int[])[] are the same thing

Re: null Vs [] return arrays

2011-03-27 Thread Jonathan M Davis
On 2011-03-27 11:42, bearophile wrote: Kagamin: [] is not null, it's an array of 0 elements, what is done exactly. edx points to the allocated array. I don't understand what you say. I think the caller of foo() and bar() receive the same thing, two empty registers. I think that

Re: null Vs [] return arrays

2011-03-27 Thread bearophile
Jonathan M Davis: the compiler can likely make assumptions about null that it can't make about [], since it probably treats [] more generally without worrying about the fact that it happens to be empty as far as optimizations go - that and there _is_ a semantic difference between null