Thread overview
What about C's -> ?
Jul 24, 2007
Hoenir
Jul 24, 2007
freeagle
Jul 24, 2007
Bill Baxter
Jul 24, 2007
freeagle
Jul 25, 2007
Jason House
Jul 24, 2007
freeagle
July 24, 2007
There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ?
July 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++
July 24, 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
July 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
July 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
July 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**'
July 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
July 25, 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