digitalmars.D.learn - What about C's -> ?
- Hoenir <mrmocool gmx.de> Jul 24 2007
- freeagle <dalibor.free gmail.com> Jul 24 2007
- Bill Baxter <dnewsgroup billbaxter.com> Jul 24 2007
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Jul 24 2007
- freeagle <dalibor.free gmail.com> Jul 24 2007
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Jul 24 2007
- Jason House <jason.james.house gmail.com> Jul 25 2007
- freeagle <dalibor.free gmail.com> Jul 24 2007
There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ?
Jul 24 2007
Hoenir wrote:There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ?
dot operator stands for both dot and -> operators in c++
Jul 24 2007
freeagle wrote:Hoenir wrote:There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ?
dot operator stands for both dot and -> operators in c++
Just curious -- does it also work for (**p).x and (***p).x etc? (Sorry to lazy to check :-P ) But surely someone here knows right off the top of their head. --bb
Jul 24 2007
Bill Baxter wrote:freeagle wrote:Hoenir wrote:There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ?
dot operator stands for both dot and -> operators in c++
Just curious -- does it also work for (**p).x and (***p).x etc? (Sorry to lazy to check :-P ) But surely someone here knows right off the top of their head. --bb
As far as I recall, yes. The '.' will "continuously" dereference until it hits something solid, and then offset appropriately from there. Although I rarely have had more than (*p) in my experience with D. (And usually only with referencing elements from arrays of structures, and with using the 'in' operator on associative arrays.) -- Chris Nicholson-Sauls
Jul 24 2007
nope, it does not:
import tango.io.Stdout;
class Test
{
int a;
}
int main(char[][] args)
{
Test a = new Test();
a.a = 13123;
Test* pa = &a;
Test** ppa = &pa;
Test*** pppa = &ppa;
Stdout(pppa.a).newline;
return 0;
}
test.d(16): Error: no property 'a' for type 'Test**'
Jul 24 2007
freeagle wrote:nope, it does not: import tango.io.Stdout; class Test { int a; } int main(char[][] args) { Test a = new Test(); a.a = 13123; Test* pa = &a; Test** ppa = &pa; Test*** pppa = &ppa; Stdout(pppa.a).newline; return 0; } test.d(16): Error: no property 'a' for type 'Test**'
Well I'll be darned. :) If this usage is actually cropping up, then I guess there ought to be a feature request put in for it. (In hand tooled code, its no big issue just to partially dereference in place, but in generic code from templates, mixins, what have you, this could potentially be hazardous.) -- Christopher Nicholson-Sauls
Jul 24 2007
freeagle wrote:nope, it does not: import tango.io.Stdout; class Test { int a; } int main(char[][] args) { Test a = new Test(); a.a = 13123; Test* pa = &a; Test** ppa = &pa; Test*** pppa = &ppa; Stdout(pppa.a).newline; return 0; } test.d(16): Error: no property 'a' for type 'Test**'
pppa.a -> fails test.d(16): Error: no property 'a' for type 'Test**' pppa...a -> fails test.d(16): found '...' when expecting ',' pppa. . .a -> fails test.d(16): identifier expected following '.', not '.' (**pppa).a -> works (***pppa).a -> works
Jul 25 2007
btw, you can find good tutorials at http://www.dsource.org and http://www.prowiki.org/wiki4d/wiki.cgi?FrontPage that will answer most of your questions. And if you need something more specific ( but a bit less understandable ), look at D's homepage for language specifications
Jul 24 2007









Chris Nicholson-Sauls <ibisbasenji gmail.com> 