digitalmars.D - Automagic length of static arrays
- Vathix (8/8) Aug 22 2005 As everyone knows, C will magically know the length of the array when
- Hasan Aljudy (2/10) Aug 22 2005 looks good to me.
- Manfred Nowak (18/20) Aug 22 2005 Maybe. But why is the D-way wrong, i.e. using a `.' when it suffices?
- Hasan Aljudy (10/41) Aug 22 2005 Because D doesn't do that! I think you are referring to D using '.'
- Freejack (13/21) Aug 27 2005 Sounds alright.
As everyone knows, C will magically know the length of the array when leaving out the number of elements if specifying an initializer like so, char foo[] = "abcde"; and as you know, that's not going to happen the same way in D because that's how to declare a dynamic array. So I have an idea to allow D to support C's magic with the following D syntax: char[$] foo = "abcde"; good?
Aug 22 2005
Vathix wrote:As everyone knows, C will magically know the length of the array when leaving out the number of elements if specifying an initializer like so, char foo[] = "abcde"; and as you know, that's not going to happen the same way in D because that's how to declare a dynamic array. So I have an idea to allow D to support C's magic with the following D syntax: char[$] foo = "abcde"; good?looks good to me.
Aug 22 2005
Vathix <chris dprogramming.com> wrote: [...]char[$] foo = "abcde"; good?Maybe. But why is the D-way wrong, i.e. using a `.' when it suffices? Saves two characters to type in addition. char. foo = "That is the point"; Ahh, I see, that will turn all assignments to fields or properties into a declaration. But D already has for ranges `[0..1]' the special <decimal number><point><point> - token which is to my knowledge unique in the world of computer languages. So why not define the <Identifier><point><point> - token to be the automagic length inheretor? char..foo = "That is the D way"; -manfred ;-) P.S.: I really forget the range special point when posting http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/27953
Aug 22 2005
Manfred Nowak wrote:Vathix <chris dprogramming.com> wrote: [...]Because D doesn't do that! I think you are referring to D using '.' instead of '->' for pointers? It's erroneous to claim that using a dot every where is the D way.char[$] foo = "abcde"; good?Maybe. But why is the D-way wrong, i.e. using a `.' when it suffices? Saves two characters to type in addition. char. foo = "That is the point";Ahh, I see, that will turn all assignments to fields or properties into a declaration. But D already has for ranges `[0..1]' the special <decimal number><point><point> - token which is to my knowledge unique in the world of computer languages. So why not define the <Identifier><point><point> - token to be the automagic length inheretor? char..foo = "That is the D way"; -manfred ;-) P.S.: I really forget the range special point when posting http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/27953Well, char[$] makes more sense, because $ is already used to refer to the array's length, and because we usually put the length inside [brackets] when declaring a statically allocated array, so the concept already has some roots. OTOH, char..foo means "from char to foo"!!!!!!! That makes no sense if you ask me.
Aug 22 2005
On Mon, 22 Aug 2005 05:41:35 -0400, Vathix wrote:As everyone knows, C will magically know the length of the array when leaving out the number of elements if specifying an initializer like so, char foo[] = "abcde"; and as you know, that's not going to happen the same way in D because that's how to declare a dynamic array. So I have an idea to allow D to support C's magic with the following D syntax: char[$] foo = "abcde"; good?Sounds alright. I'm new to D, but I've been doing C, Ada, and Assembler for better than ten years now. One thing that chaffes my ass about C style arrays(or imperative language arrays in general) is the error prone and tedious indexing. I think a better solution would be to just switch to APL style arrays and array handling(using D syntax of course). I like D, and for all it's advancements, it's still stuck in the dark ages for array manipulation. char[$] foo = "blah"; shouldn't be necessary with a language sporting the features of D. APL style arrays would certainly give D a leg up and over it's competitors. My .02 worth. Freejack
Aug 27 2005