digitalmars.D - circular deps
- Scott (25/25) May 17 2007 Hi all,
- Jarrett Billingsley (7/31) May 17 2007 I would imagine that you have more code (so for example, vec3 really doe...
- Scott (5/12) May 18 2007 Yeah, this is the code stripped down to its most minimal form that still...
- Manfred Nowak (25/26) May 18 2007 The correct ways in the given case are at least
Hi all, Whats the correct way to use imports to handle the following type of circular dependency? //main.d --------------8<--------------- import vec3, mat3, quat; int main() { return 0; } // mat3.d--------------8<--------------- module mat3; import vec3, quat; struct Mat3 { Vec3[3] m; } // quat.d--------------8<--------------- module quat; import vec3, mat3; struct Quat {} // vec3.d--------------8<--------------- module vec3; import mat3, quat; struct Vec3 { } I get this back from the compiler.... unixbox$ dmd main.d vec3.d mat3.d quat.d vec3.d(6): struct vec3.Vec3 no size yet for forward reference vec3.d(6): struct vec3.Vec3 no size yet for forward reference vec3.d(6): struct vec3.Vec3 no size yet for forward reference unixbox$ Thanks S
May 17 2007
"Scott" <bob zone.com> wrote in message news:f2houk$2l1a$1 digitalmars.com...Hi all, Whats the correct way to use imports to handle the following type of circular dependency? //main.d --------------8<--------------- import vec3, mat3, quat; int main() { return 0; } // mat3.d--------------8<--------------- module mat3; import vec3, quat; struct Mat3 { Vec3[3] m; } // quat.d--------------8<--------------- module quat; import vec3, mat3; struct Quat {} // vec3.d--------------8<--------------- module vec3; import mat3, quat; struct Vec3 { } I get this back from the compiler.... unixbox$ dmd main.d vec3.d mat3.d quat.d vec3.d(6): struct vec3.Vec3 no size yet for forward reference vec3.d(6): struct vec3.Vec3 no size yet for forward reference vec3.d(6): struct vec3.Vec3 no size yet for forward reference unixbox$I would imagine that you have more code (so for example, vec3 really does depend on mat3 and quat). As far as I'm concerned, this is a bug in the compiler that Walter has never been particularly intent on fixing. I've always ended up just clumping any circularly-dependent modules into one file, even if it doesn't really make sense to. Makes the compiler shut up.
May 17 2007
Yeah, this is the code stripped down to its most minimal form that still causes the compiler to barf. If someone can tell me for sure that this is a compiler bug, I'll have a go at fixing it myself. Cheers S Jarrett Billingsley Wrote:I would imagine that you have more code (so for example, vec3 really does depend on mat3 and quat). As far as I'm concerned, this is a bug in the compiler that Walter has never been particularly intent on fixing. I've always ended up just clumping any circularly-dependent modules into one file, even if it doesn't really make sense to. Makes the compiler shut up.
May 18 2007
Scott wroteWhats the correct way to use importsThe correct ways in the given case are at least - to compile by `dmd mat3 main' - to change the import declaration in "main.d" so that `mat3' is imported before `vec3' - to change the position of the import declaration in "vec3.d" so that it follows lexically the definition of type `Vec3' All these ways enable the compiler to destroy the cyclic importing in the given case. But according to the specs the compiler is indeed buggy. The specs say: | The order in which ImportDeclarations occur has no significance. With your slightly modified example the compiler continues to emit errors if the import declaration `import vec3, mat3, quat;' is changed to import vec3; import mat3; import quat; But the error vanishes on changing the order to import mat3; import vec3; import quat; This is the proof that the order indeed has a significance for the compiler. -manfred
May 18 2007