Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 19, 2003 Circular Imports | ||||
---|---|---|---|---|
| ||||
I was curious what happens in the following situation: a.d --- import b; class A { B x; } --- b.d --- import a; class B { A x; } it didn't generate any compile-time errors, so I'm wondering what exactly happens with it. |
March 19, 2003 Re: Circular Imports | ||||
---|---|---|---|---|
| ||||
Posted in reply to Deja Augustine | Deja Augustine wrote:
> I was curious what happens in the following situation:
>
> a.d
> ---
> import b;
>
> class A
> {
> B x;
> }
>
> ---
> b.d
> ---
> import a;
>
> class B
> {
> A x;
> }
>
>
> it didn't generate any compile-time errors, so I'm wondering what exactly
> happens with it.
D, unlike C, splits semantic phases into a set of stages. In the initial parsing it sees B and A fields in one and the other and doesn't try to interpret it; it's only in the semantic phases that it links them together. It should also be possible to do this:
class B : A { }
class A { }
And this:
class A { B x; }
struct B { }
And this:
A x = { 1, 2 };
struct A { int a, b; }
|
March 19, 2003 Re: Circular Imports | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:b595vf$25cs$1@digitaldaemon.com... > Deja Augustine wrote: > > I was curious what happens in the following situation: > > > > a.d > > --- > > import b; > > > > class A > > { > > B x; > > } > > > > --- > > b.d > > --- > > import a; > > > > class B > > { > > A x; > > } > > > > > > it didn't generate any compile-time errors, so I'm wondering what exactly > > happens with it. > > D, unlike C, splits semantic phases into a set of stages. In the initial parsing it sees B and A fields in one and the other and doesn't try to interpret it; it's only in the semantic phases that it links them together. It should also be possible to do this: > > class B : A { } > class A { } > > And this: > > class A { B x; } > struct B { } > > And this: > > A x = { 1, 2 }; > struct A { int a, b; } > Yeah, that's not really what I was asking. What I wanted to know was, can someone, using my initial example, write a chunk of code like so: ----- c.d ----- import a; B var; int main() { var.x = new A(); var.x.x = new B(); var.x.x.x = new A(); } on into infinity |
March 19, 2003 Re: Circular Imports | ||||
---|---|---|---|---|
| ||||
Posted in reply to Deja Augustine | Deja Augustine wrote:
> Yeah, that's not really what I was asking. What I wanted to know was, can
> someone, using my initial example, write a chunk of code like so:
> -----
> c.d
> -----
> import a;
>
> B var;
>
> int main()
> {
> var.x = new A();
> var.x.x = new B();
> var.x.x.x = new A();
> }
>
> on into infinity
Yes, because they're classes. If they were struct, it would be a circular field error.
|
March 19, 2003 Re: Circular Imports | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:b59753$263r$1@digitaldaemon.com... > Deja Augustine wrote: > > Yeah, that's not really what I was asking. What I wanted to know was, can > > someone, using my initial example, write a chunk of code like so: > > ----- > > c.d > > ----- > > import a; > > > > B var; > > > > int main() > > { > > var.x = new A(); > > var.x.x = new B(); > > var.x.x.x = new A(); > > } > > > > on into infinity > > Yes, because they're classes. If they were struct, it would be a circular field error. > Okay. As a side note treat for anyone reading this, I hope to have DEnv Beta 1.2f out sometime this week. |
Copyright © 1999-2021 by the D Language Foundation