Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
July 24, 2007 What about C's -> ? | ||||
---|---|---|---|---|
| ||||
There seems to be no p->x in D. Is there any other syntactic sugar for (*p).x ? |
July 24, 2007 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to freeagle | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to freeagle | 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 Re: What about C's -> ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to freeagle | 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
|
Copyright © 1999-2021 by the D Language Foundation