digitalmars.D - D bug? or user error?
- clayasaurus (44/44) May 20 2004 hi, i'm getting seg faults with the following program code.
- Andy Friesen (5/30) May 20 2004 Maybe if this problem pops up on the newsgroup enough, Walter will cave
- clayasaurus (2/19) May 20 2004
- DemmeGod (3/36) May 20 2004 A compiler check would certainly make it easier for C++ guys to adopt D,
- J C Calvarese (7/43) May 20 2004 For what it's worth (probably not much), I've already put this error on
hi, i'm getting seg faults with the following program code. i'm using Slack 9 linux with dmd v0.89. I type dmd bug.d, it compiles, and when i run the program ./bug I get the following output... "bug: before crash Segmentation fault" the things is, I can't possibly understand what I'm doing wrong. If I am doing something wrong, can someone please point it out to me? or have I discovered a D bug? thx. - clayasaurus ///////////////////////////////////////////////////////////////////////////// // bug.d - is this my error? or some D bug? class cNew { public: void set(float num) { m_x = m_y = m_z = num; assert(m_x == m_y == m_z == num); } private: float m_x, m_y, m_z; } class cCrash { public: this() { m_new.set(0); // is this so harmful? } private: cNew m_new; } int main(char[][] argv) { printf("bug: before crash\n"); cCrash crash = new cCrash(); // <-- it must crash in here... printf("bug: after crash\n"); // note: it Seg faults before it gets here on Slack 9 linux return 0; } // end /////////////////////////////////////////////////////////////////////////////
May 20 2004
clayasaurus wrote:class cNew { public: void set(float num) { m_x = m_y = m_z = num; assert(m_x == m_y == m_z == num); } private: float m_x, m_y, m_z; } class cCrash { public: this() {m_new is a null reference. You need to allocate a cNew first.m_new.set(0); // is this so harmful? } private: cNew m_new; }Maybe if this problem pops up on the newsgroup enough, Walter will cave and make the compiler check. :) -- andy
May 20 2004
oh ok, hehe. Well, that's cool, simple, elegant D at it again *doh!* In article <c8jj0r$plo$1 digitaldaemon.com>, Andy Friesen says...clayasaurus wrote:class cCrash { public: this() {m_new is a null reference. You need to allocate a cNew first.m_new.set(0); // is this so harmful? } private: cNew m_new; }Maybe if this problem pops up on the newsgroup enough, Walter will cave and make the compiler check. :) -- andy
May 20 2004
A compiler check would certainly make it easier for C++ guys to adopt D, Walter. :) On Thu, 20 May 2004 17:41:07 -0700, Andy Friesen wrote:clayasaurus wrote:class cNew { public: void set(float num) { m_x = m_y = m_z = num; assert(m_x == m_y == m_z == num); } } private: float m_x, m_y, m_z; } } class cCrash { public: this() {m_new is a null reference. You need to allocate a cNew first.m_new.set(0); // is this so harmful? } } private: cNew m_new; } }Maybe if this problem pops up on the newsgroup enough, Walter will cave and make the compiler check. :) -- andy
May 20 2004
Andy Friesen wrote:clayasaurus wrote:For what it's worth (probably not much), I've already put this error on my list of common errors: http://www.wikiservice.at/d/wiki.cgi?ErrorMessages#Un-initializedObject -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/class cNew { public: void set(float num) { m_x = m_y = m_z = num; assert(m_x == m_y == m_z == num); } private: float m_x, m_y, m_z; } class cCrash { public: this() {m_new is a null reference. You need to allocate a cNew first.m_new.set(0); // is this so harmful? } private: cNew m_new; }Maybe if this problem pops up on the newsgroup enough, Walter will cave and make the compiler check. :) -- andy
May 20 2004