|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
D - Another compiler bug? Static struct functions...
OK, I wrote about it in different thread, but maybe it will be better to
start a new one. For me it seems (due to error message I get) that this
is a compiler problem (not to mention the code compiled for some time...)
This is the offending code. It gives following error, at this line in
the "cross" procedure:
return frVector.make(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
Error:
"undefined identifier module frVector.make"
(which looks like compiler thinks "make" is a module in subdirectory
"frVector", right?)
import c.stdio;
import std.math;
alias double frReal;
struct frVector
{
// aby odwoływać się do nich jako x y z i tablicy
union {
struct{ frReal x; frReal y; frReal z;}; frReal w[3];
}
// niby-konstruktor
static frVector make(frReal xx, frReal yy, frReal zz){
frVector result;
result.x=xx; result.y=yy; result.z=zz;
return result;
}
// użytkowe
void set(frReal xx, frReal yy, frReal zz) {
x=xx; y=yy; z=zz;
}
void set(frVector vv) {
x=vv.x; y=vv.y; z=vv.z;
}
frReal opIndex(int i)
{
return w[i];
}
frReal opIndex(int i, frReal val)
{
w[i]=val;
return val;
}
void print() {
printf("(%f,%f,%f)\n",x,y,z);
}
// ze skalarem
frVector opMul(frReal sc){
return frVector.make(x*sc, y*sc, z*sc);
}
frVector opDiv(frReal sc){
return frVector.make(x/sc, y/sc, z/sc);
}
void opDivAssign(frReal sc){
x=x/sc; y=y/sc; z=z/sc;
}
// unarne
frVector opNeg() {
frVector vv;
return frVector.make(-x,-y,-z);
}
// z wektorem
frVector opAdd(frVector vv){
return frVector.make(vv.x+x,vv.y+y,vv.z+z);
}
frVector opSub(frVector vv){
return frVector.make(vv.x-x,vv.y-y,vv.z-z);
}
frVector opMul(frVector vv){
return frVector.make(vv.x*x,vv.y*y,vv.z*z);
}
frVector opDiv(frVector vv){
return frVector.make(vv.x/x,vv.y/y,vv.z/z);
}
frReal dot(frVector v) {
return x*v.x + y*v.y + z*v.z;
}
frVector cross(frVector v) {
return frVector.make(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
}
// inne
frReal magnitudeSquared(){
return x*x + y*y + z*z;
}
frReal magnitude(){
return sqrt(x*x + y*y + z*z);
}
void normalize(){
(*this)/=magnitude;
}
}
Dec 19 2003
"ssuukk" <ssuukk .go2.pl> wrote in message
news:brudqd$djh$1 digitaldaemon.com...
| OK, I wrote about it in different thread, but maybe it will be better to
| start a new one. For me it seems (due to error message I get) that this
| is a compiler problem (not to mention the code compiled for some time...)
|
| This is the offending code. It gives following error, at this line in
| the "cross" procedure:
|
| return frVector.make(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
|
| Error:
|
| "undefined identifier module frVector.make"
|
| (which looks like compiler thinks "make" is a module in subdirectory
| "frVector", right?)
|
|
|
|
| import c.stdio;
| import std.math;
|
| alias double frReal;
|
| struct frVector
| {
| // aby odwoływać się do nich jako x y z i tablicy
| union {
| struct{ frReal x; frReal y; frReal z;}; frReal w[3];
| }
|
| // niby-konstruktor
| static frVector make(frReal xx, frReal yy, frReal zz){
| frVector result;
| result.x=xx; result.y=yy; result.z=zz;
| return result;
| }
| ...
You need to put "make" inside frVector. Or you should make the call just as
"make" and not "frVector.make"
-----------------------
Carlos Santander Bernal
Dec 19 2003
Dec 19 2003
"ssuukk" <ssuukk .go2.pl> wrote in message news:bruqgc$vp8$1 digitaldaemon.com... | But make IS inside frVector struct! :-O | My mistake: you're right. And that's the same reason why your code compiles for me. Even a call to frVector.make. ----------------------- Carlos Santander Bernal Dec 19 2003
Carlos Santander B. wrote:"ssuukk" <ssuukk .go2.pl> wrote in message news:bruqgc$vp8$1 digitaldaemon.com... | But make IS inside frVector struct! :-O | My mistake: you're right. And that's the same reason why your code compiles for me. Even a call to frVector.make. Dec 19 2003
ssuukk <ssuukk .go2.pl> wrote in news:bruvbc$1745$1 digitaldaemon.com:Carlos Santander B. wrote:"ssuukk" <ssuukk .go2.pl> wrote in message news:bruqgc$vp8$1 digitaldaemon.com... | But make IS inside frVector struct! :-O | My mistake: you're right. And that's the same reason why your code compiles for me. Even a call to frVector.make. Dec 19 2003
My mistake: you're right. And that's the same reason why your code compiles for me. Even a call to frVector.make. Dec 19 2003
In article <brv3to$1do9$1 digitaldaemon.com>, ssuukk says...My mistake: you're right. And that's the same reason why your code compiles for me. Even a call to frVector.make. Dec 19 2003
|