Re: char[] == null

2015-11-20 Thread Maxim Fomin via Digitalmars-d-learn
On Thursday, 19 November 2015 at 15:36:44 UTC, Steven Schveighoffer wrote: On 11/19/15 3:30 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, November 18, 2015 22:15:19 anonymous via Digitalmars-d-learn wrote: On 18.11.2015 22:02, rsw0x wrote: slices aren't arrays

Re: char[] == null

2015-11-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 18, 2015 22:15:19 anonymous via Digitalmars-d-learn wrote: > On 18.11.2015 22:02, rsw0x wrote: > > slices aren't arrays > > http://dlang.org/d-array-article.html > > The language reference/specification [1] uses the term "dynamic array" > for T[] types. Let's not enforce a

Re: char[] == null

2015-11-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 19 November 2015 at 03:53:48 UTC, Meta wrote: On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: --- char[] buffer; if (buffer.length == 0) {} --- This is not true. Consider the following code: import std.stdio; void main() { int[] a = [0, 1, 2];

Re: char[] == null

2015-11-19 Thread Spacen Jasset via Digitalmars-d-learn
) made the mistake of calling the buffer that T[] points to on the GC heap (assuming that even does point to the GC heap) the dynamic array. And per the language spec, that's not true at all. [...] I mentioned this because it's bit of an error trap, that I fell into. char[] == null vs char

Re: char[] == null

2015-11-19 Thread Jack Applegame via Digitalmars-d-learn
I prefer import std.array; if(!arr.empty) {}

Re: char[] == null

2015-11-19 Thread BBaz via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 20:57:08 UTC, Spacen Jasset wrote: Should this be allowed ? IMHO no. It's better to use `.length` to test if an array is empty. Why ? Because the day you'll have a function whose parameter is a pointer to an array, comparing to null will become completly

Re: char[] == null

2015-11-19 Thread Chris Wright via Digitalmars-d-learn
On Thu, 19 Nov 2015 07:28:28 +0100, anonymous wrote: > On 19.11.2015 06:18, Chris Wright wrote: >> Just for fun, is an array ever not equal to itself? > > Yes, when it contains an element that's not equal to itself, e.g. NaN. Exactly. If NaN-like cases didn't exist, TypeInfo_Array could have

Re: char[] == null

2015-11-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 19 November 2015 at 10:04:37 UTC, Spacen Jasset wrote: char[] == null vs char[] is null Is there any good use for char[] == null ? If not, a warning might be helpful. Actually char[] == null is a more usable one.

Re: char[] == null

2015-11-19 Thread Steven Schveighoffer via Digitalmars-d-learn
into. char[] == null vs char[] is null Is there any good use for char[] == null ? If not, a warning might be helpful. Of course, if you are comparing something to an empty array, null is an effective literal to create one. -Steve

Re: char[] == null

2015-11-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/19/15 3:30 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, November 18, 2015 22:15:19 anonymous via Digitalmars-d-learn wrote: On 18.11.2015 22:02, rsw0x wrote: slices aren't arrays http://dlang.org/d-array-article.html The language reference/specification [1] uses

Re: char[] == null

2015-11-19 Thread Meta via Digitalmars-d-learn
On Thursday, 19 November 2015 at 13:49:18 UTC, Meta wrote: On Thursday, 19 November 2015 at 06:57:20 UTC, Jack Applegame wrote: Really? http://dpaste.dzfl.pl/b11346e8e341 Sorry, I said the exact opposite of what I meant to say. The `assert(a == null)` *is* triggered because the expression `a

Re: char[] == null

2015-11-19 Thread Meta via Digitalmars-d-learn
On Thursday, 19 November 2015 at 06:57:20 UTC, Jack Applegame wrote: Really? http://dpaste.dzfl.pl/b11346e8e341 Sorry, I said the exact opposite of what I meant to say. The `assert(a == null)` *is* triggered because the expression `a == null` fails, even though a.length == 0. You should not

char[] == null

2015-11-18 Thread Spacen Jasset via Digitalmars-d-learn
Should this be allowed? What is it's purpose? It could compare two arrays, but surely not that each element of type char is null? char[] buffer; if (buffer == null) {}

Re: char[] == null

2015-11-18 Thread Chris Wright via Digitalmars-d-learn
On Wed, 18 Nov 2015 20:57:06 +, Spacen Jasset wrote: > Should this be allowed? What is it's purpose? It could compare two > arrays, but surely not that each element of type char is null? > > char[] buffer; > if (buffer == null) {} 'null' is a value of ambiguous type. The compiler finds a

Re: char[] == null

2015-11-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: --- char[] buffer; if (buffer.length == 0) {} --- This is not true. Consider the following code: import std.stdio; void main() { int[] a = [0, 1, 2]; //4002E000 3 writeln(a.ptr, " ", a.length);

Re: char[] == null

2015-11-18 Thread Chris Wright via Digitalmars-d-learn
On Thu, 19 Nov 2015 03:53:46 +, Meta wrote: > On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: >> --- >> char[] buffer; >> if (buffer.length == 0) {} >> --- > > This is not true. Consider the following code: > > import std.stdio; > > void main() > { > int[] a = [0,

Re: char[] == null

2015-11-18 Thread anonymous via Digitalmars-d-learn
On 19.11.2015 06:18, Chris Wright wrote: Just for fun, is an array ever not equal to itself? Yes, when it contains an element that's not equal to itself, e.g. NaN.

Re: char[] == null

2015-11-18 Thread Jack Applegame via Digitalmars-d-learn
On Thursday, 19 November 2015 at 03:53:48 UTC, Meta wrote: On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: [...] This is not true. Consider the following code: import std.stdio; void main() { int[] a = [0, 1, 2]; //4002E000 3 writeln(a.ptr, " ",

Re: char[] == null

2015-11-18 Thread rsw0x via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 20:57:08 UTC, Spacen Jasset wrote: Should this be allowed? What is it's purpose? It could compare two arrays, but surely not that each element of type char is null? char[] buffer; if (buffer == null) {} slices aren't arrays

Re: char[] == null

2015-11-18 Thread anonymous via Digitalmars-d-learn
On 18.11.2015 22:02, rsw0x wrote: slices aren't arrays http://dlang.org/d-array-article.html The language reference/specification [1] uses the term "dynamic array" for T[] types. Let's not enforce a slang that's different from that. [1] http://dlang.org/arrays.html