Thread overview
int*[5] array;
Jun 08, 2002
Dario
Jun 12, 2002
Walter
Jun 17, 2002
Dario
Jun 18, 2002
Walter
Jun 26, 2002
OddesE
June 08, 2002
Arrays are declared with the [] after the identifier. This leads to very
clumsy syntax to declare things like a pointer to an array:
    int (*array)[3];
In D, the [] for the array go on the left:
    int[3] *array;        //declares a pointer to an array of 3 ints
    long[] func(int x);        //declares a function returning an array of
longs
which is much simpler to understand.
_____________________________________________________

Doesn't this syntax look strange?
The C code:
    int * array[5];
corresponds to the D code:
    int*[5] array;

You say the second one is easier to understand. I agree but this is
inconsistent: you dereference it with:
    int something = *array[5];
and not with:
    int something = array*[5];
or:
    int something = *[5]array;

In C the declaration was very similar to the dereferencing sintax. D is inconsistent about it.

((( sorry for my English, that's orrible...)))    ;-)


June 12, 2002
"Dario" <supdar@yahoo.com> wrote in message news:adt7d4$mb6$1@digitaldaemon.com...
> _____________________________________________________
>
> Doesn't this syntax look strange?
> The C code:
>     int * array[5];
> corresponds to the D code:
>     int*[5] array;
>
> You say the second one is easier to understand. I agree but this is
> inconsistent: you dereference it with:
>     int something = *array[5];
> and not with:
>     int something = array*[5];
> or:
>     int something = *[5]array;
>
> In C the declaration was very similar to the dereferencing sintax. D is inconsistent about it.

Yes, you're right. But D still does allow the [] after the identifier as
well, i.e.:
    int[] foo;
    int foo[];
are both declaring foo to be an array of ints.


June 17, 2002
> > Doesn't this syntax look strange?
> > The C code:
> >     int * array[5];
> > corresponds to the D code:
> >     int*[5] array;
> >
> > You say the second one is easier to understand. I agree but this is
> > inconsistent: you dereference it with:
> >     int something = *array[5];
> > and not with:
> >     int something = array*[5];
> > or:
> >     int something = *[5]array;
> >
> > In C the declaration was very similar to the dereferencing sintax. D is inconsistent about it.

> Yes, you're right. But D still does allow the [] after the identifier as
> well, i.e.:
>     int[] foo;
>     int foo[];
> are both declaring foo to be an array of ints.

But the first one is the official one: d programmers are all going to use
the first one.
You wrote that "int[]* vector;" is better because it is simpler than "int
(*vector)[];".
But you already use the old sintax for dereferencing. So maybe we should be
able to use the new syntax everywhere (a postfix operator?).


June 18, 2002
"Dario" <supdar@yahoo.com> wrote in message news:aekb3c$1hsb$1@digitaldaemon.com...
> But the first one is the official one: d programmers are all going to use the first one.

Yes.

> You wrote that "int[]* vector;" is better because it is simpler than "int
> (*vector)[];".

Yes.

> But you already use the old sintax for dereferencing. So maybe we should
be
> able to use the new syntax everywhere (a postfix operator?).

Sometimes, complete consistency may not be worth it <g>.


June 18, 2002
"Dario" <supdar@yahoo.com> wrote in message news:aekb3c$1hsb$1@digitaldaemon.com...

> But you already use the old sintax for dereferencing. So maybe we should
be
> able to use the new syntax everywhere (a postfix operator?).

   Hmmm... The old syntax IS a postfix operator. Kinda.

   Anyway, I never understood why some people think that defining a variable
and using it must use the same syntax. I always loved Pascal-type syntax for
declaring:

f: pointer to array of int;
g: array[1..7] of pointer to array[1..10] of array[1..2] of float;

Salutaciones,
                         JCAB



June 26, 2002
"Juan Carlos Arevalo Baeza" <jcab@roningames.com> wrote in message news:aenq65$2l2t$1@digitaldaemon.com...
> "Dario" <supdar@yahoo.com> wrote in message news:aekb3c$1hsb$1@digitaldaemon.com...
>
> > But you already use the old sintax for dereferencing. So maybe we should
> be
> > able to use the new syntax everywhere (a postfix operator?).
>
>    Hmmm... The old syntax IS a postfix operator. Kinda.
>
>    Anyway, I never understood why some people think that defining a
variable
> and using it must use the same syntax. I always loved Pascal-type syntax
for
> declaring:
>
> f: pointer to array of int;
> g: array[1..7] of pointer to array[1..10] of array[1..2] of float;
>
> Salutaciones,
>                          JCAB
>



I agree.
Verbose as it is, it is very easy to understand and
it reads the 'right' way (pun intended). However it
is totally inconsistant for C and therefore also for D.

I think complex declarations such as these prove
that in the end, pascal's left-to-right declarations
make much more sense than C's right-to-left ones...
The fact that Walter and everyone on this group still
didn't come up with a C-style syntax for declaring
compex pointer to arrays of pointers to etc, that is
really clear and consistant, is something that should
inspire some serious thought.


--
Stijn
OddesE_XYZ@hotmail.com
http://OddesE.cjb.net
_________________________________________________
Remove _XYZ from my address when replying by mail




June 27, 2002
"OddesE" <OddesE_XYZ@hotmail.com> wrote in message news:afd93d$2d7k$1@digitaldaemon.com...
> "Juan Carlos Arevalo Baeza" <jcab@roningames.com> wrote in message news:aenq65$2l2t$1@digitaldaemon.com...
>
> > f: pointer to array of int;
> > g: array[1..7] of pointer to array[1..10] of array[1..2] of float;
>
> I agree.
> Verbose as it is, it is very easy to understand and
> it reads the 'right' way (pun intended).

   Exactly!

> However it
> is totally inconsistant for C and therefore also for D.

   What you mean, I believe, is that type declarations are not written
exactly the same way as using objects of the type. Now, I've never
understood why some people consider it that important.

   Clarity and lack of ambiguity are much better properties, IMHO.

   Still, it is not perfect. For example, I love the fact that (unlike in
LX) the name is separate from the type expression. But it has a problem with
initializers:

f = NULL: pointer to array of int;
f: pointer to array of int = NULL;

   The second form sounds a little better, maybe (easier to parse?), but it
breaks with multiple-variable initialization:

f = NULL, g = &myarray: pointer to array of int;
f, g: pointer to array of int = NULL, &myarray; // Ugh!

   And also, I still like using puntuation rather than keywords wherever
possible (it's easier to spot at a glance):

f = NULL, g = &myarray: *[]int; // Better?

   Of course, this deviates from the general C/C++ norm, which makes it
maybe not desirable to D. It's just a matter of weighing the advantages and
disadvantages, which is Walter's prerogative.

> I think complex declarations such as these prove
> that in the end, pascal's left-to-right declarations
> make much more sense than C's right-to-left ones...
> The fact that Walter and everyone on this group still
> didn't come up with a C-style syntax for declaring
> compex pointer to arrays of pointers to etc, that is
> really clear and consistant, is something that should
> inspire some serious thought.

   Definitely.

Salutaciones,
                         JCAB