Re: How to be more careful about null pointers?

2016-03-29 Thread QAston via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote: I finally found the null pointer. It took a week. I was assigning "db = db" when I should have been assigning "this.db = db". Terrible, I know. But... I invoked db.find_chapter.bindAll(8,4), when db was a null pointer. There was no null

Re: How to be more careful about null pointers?

2016-03-29 Thread Marco Leise via Digitalmars-d-learn
Am Tue, 29 Mar 2016 06:00:32 + schrieb cy : > struct Database { >string derp; >Statement prepare(string s) { > return Statement(1234); >} > } > > struct Statement { >int member; >void bind(int column, int value) { > import std.stdio; >

Re: How to be more careful about null pointers?

2016-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 03/29/2016 11:57 AM, cy wrote: > On Tuesday, 29 March 2016 at 06:21:49 UTC, Ali Çehreli wrote: >> parent.prep.bind is translated to the following by the compiler: >> >> "Call bind() for the object at address... let's calculate... Wherever >> parent is, we should add the offset of prep inside

Re: How to be more careful about null pointers?

2016-03-29 Thread cy via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 06:21:49 UTC, Ali Çehreli wrote: parent.prep.bind is translated to the following by the compiler: "Call bind() for the object at address... let's calculate... Wherever parent is, we should add the offset of prep inside that object." Okay, that's helpful

Re: How to be more careful about null pointers?

2016-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 03/28/2016 11:00 PM, cy wrote: > struct Database { >string derp; >Statement prepare(string s) { > return Statement(1234); >} > } > > struct Statement { >int member; >void bind(int column, int value) { > import std.stdio; > writeln("derp",member); Change

Re: How to be more careful about null pointers?

2016-03-29 Thread cy via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:24:48 UTC, Adam D. Ruppe wrote: If it didn't give the error, either you swallowed it or you didn't actually dereference null. Okay, so it's not actually supposed to happen. Hopefully it's something I did wrong... What is the db library you are using? Did you

Re: How to be more careful about null pointers?

2016-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote: No exception raised for dereferencing a null. If it didn't give the error, either you swallowed it or you didn't actually dereference null. The latter is a kinda strange happenstance, but if you are calling a static or final method on an

Re: How to be more careful about null pointers?

2016-03-28 Thread cy via Digitalmars-d-learn
On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote: I invoked db.find_chapter.bindAll(8,4), when db was a null pointer. No, no, no it's worse than that. What I did was (db.)find_chapter = (db.)backend.prepare("...") when backend was null, and got no error. find_chapter was garbage of course,

How to be more careful about null pointers?

2016-03-28 Thread cy via Digitalmars-d-learn
I finally found the null pointer. It took a week. I was assigning "db = db" when I should have been assigning "this.db = db". Terrible, I know. But... I invoked db.find_chapter.bindAll(8,4), when db was a null pointer. There was no null pointer error. No exception raised for dereferencing a