www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What about C's -> ?

reply Hoenir <mrmocool gmx.de> writes:
There seems to be no p->x in D. Is there any other syntactic sugar for 
(*p).x ?
Jul 24 2007
next sibling parent reply freeagle <dalibor.free gmail.com> writes:
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
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
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
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
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
parent reply freeagle <dalibor.free gmail.com> writes:
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
next sibling parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
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
prev sibling parent Jason House <jason.james.house gmail.com> writes:
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
prev sibling parent freeagle <dalibor.free gmail.com> writes:
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