Thread overview | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 04, 2002 multiple declarations | ||||
---|---|---|---|---|
| ||||
I finally got around to addressing the problems of multiple declarations in one statement. www.digitalmars.com/d/declaration.html |
February 05, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a3n5b2$20oo$1@digitaldaemon.com... > I finally got around to addressing the problems of multiple declarations in > one statement. > > www.digitalmars.com/d/declaration.html I like it. Ahem... Typo: "Declaration syntax generally reads left to right" ... "Arrays, when lexically next to each other, read right to left" "right" and "left" are switched, I believe. You know... the other right and the other left :) The thing with the arrays is nasty. But I only see two alternatives. For: x[0]; // is a int[5] x[0][0]; // Is the "first" element x[4][2]; // Is the "last" element We have: int[3][5] x; // Array of 5 arrays of 3 ints. int[3]*[5] x; // x is an array of 5 pointers to arrays of 3 ints which inverts the indices in the type specifier. Or inverting everything: [5][3]int x; // Array of 5 arrays of 3 ints. [5]*[3]int x; // x is an array of 5 pointers to arrays of 3 ints which deviates even more from C/C++. And talking about changing syntax, I'd consider: int(char)* x; // x is a pointer to a function taking a char argument // and returning an int int(char)*[] x; // x is an array of pointers to functions // taking a char argument and returning an int Salutaciones, JCAB |
February 05, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:a3n5b2$20oo$1@digitaldaemon.com... > I finally got around to addressing the problems of multiple declarations in > one statement. > > www.digitalmars.com/d/declaration.html Seems fine. Function pointers could be better, but it doesn't really matters much, since they work fine. |
February 05, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Declaration syntax generally reads right to left, not left to right....: Walter <walter@digitalmars.com> wrote in message news:a3n5b2$20oo$1@digitaldaemon.com... > I finally got around to addressing the problems of multiple declarations in > one statement. > > www.digitalmars.com/d/declaration.html > > |
February 05, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | "Pavel Minayev" <evilone@omen.ru> wrote in message news:a3o14i$2fe8$1@digitaldaemon.com... > "Walter" <walter@digitalmars.com> wrote in message news:a3n5b2$20oo$1@digitaldaemon.com... > > I finally got around to addressing the problems of multiple declarations > in > > one statement. > > > > www.digitalmars.com/d/declaration.html > > Seems fine. Function pointers could be better, but it doesn't really matters much, since they work fine. The only saving grace with function pointers is they are rarely declared, so it isn't worth spending too much effort on them. They work like in C, and that's good enough. Arrays are a different matter. I use arrays all the time, and so improving the declaration syntax for them pays off. |
February 05, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to D | "D" <s_nudds@hotmail.com> wrote in message news:a3o76d$2iue$1@digitaldaemon.com... > Declaration syntax generally reads right to left, not left to right....: Depends on which side you're looking at it from <g>. |
February 06, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Well, you are replacing clumsy C declaration syntax with more clean one, but it still follows kind of dynamic rule: "Declaration syntax generally reads left to right", except "Arrays, when lexically next to each other, read right to left". How about making it static? Each declaration contains some "basic" (or underlaying) type name optionally followed by the arrays/pointers hierarchy. Type name probably should remain at the first position (otherwise it'll end up with something like Pascal;), but all in between can be ordered strictly left to right. "Basic Type" [ arrays/pointers hierarchy : Left-to-Right ] VariableName; int[3][5] x; // x is an array of 3 arrays of 5 ints int[3]*[5] x; // x is an array of 3 pointers to arrays of 5 ints int*[] x; // x is a pointer to an array of ints int[]* x; // x is an array of pointers to ints What do you think? |
February 06, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Serge K | I'm all for it. In fact I suggested the very same thing a few weeks ago. The only major difference from what I can tell between this and the current D syntax for typespecs is that D allows the array specification to come after the variable (for minimal C compatibility I suppose). I believe the examples you give all work in D as it's currently specified. Sean "Serge K" <skarebo@programmer.net> wrote in message news:a3qnl7$22pd$1@digitaldaemon.com... > Well, you are replacing clumsy C declaration syntax with more clean one, > but it still follows kind of dynamic rule: > "Declaration syntax generally reads left to right", > except "Arrays, when lexically next to each other, read right to left". > > How about making it static? > Each declaration contains some "basic" (or underlaying) type name optionally > followed by the arrays/pointers hierarchy. Type name probably should remain > at the first position (otherwise it'll end up with something like Pascal;), > but all in between can be ordered strictly left to right. > > "Basic Type" [ arrays/pointers hierarchy : Left-to-Right ] VariableName; > > int[3][5] x; // x is an array of 3 arrays of 5 ints > int[3]*[5] x; // x is an array of 3 pointers to arrays of 5 ints > int*[] x; // x is a pointer to an array of ints > int[]* x; // x is an array of pointers to ints > > What do you think? |
February 06, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <spalmer@iname.com> wrote in message news:a3qvu7$27a5$1@digitaldaemon.com... > I'm all for it. In fact I suggested the very same thing a few weeks ago. The only major difference from what I can tell between this and the current > D syntax for typespecs is that D allows the array specification to come after the variable (for minimal C compatibility I suppose). I believe the examples you give all work in D as it's currently specified. Nah. For example, int*[] is an array of pointers now, while int[]* is a pointer to array. He suggests to reverse them. I personally consider the syntax that is there now somewhat more "intuitive" - even though it's a bit more complicated. |
February 06, 2002 Re: multiple declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | > I'm all for it. In fact I suggested the very same thing a few weeks ago. The only major difference from what I can tell between this and the current > D syntax for typespecs is that D allows the array specification to come after the variable (for minimal C compatibility I suppose). Ability to put array specification after variable name seems to be quite useless "syntactic sugar" (since "declaration declaring multiple declarations" cannot declare variables with different type). The only practical reason to use such ability is to write something like this: int a[3], b[2], c; // currently not allowed. > I believe the examples you give all work in D as it's currently specified. No, currently it works in a quite opposite & mixed way.. ;-) It's just in my opinion the language specifications should have as less "special cases" as possible. |
Copyright © 1999-2021 by the D Language Foundation