MESSAGE
DATE | 2011-03-15 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] [ruben@mrbrklyn.com: Re: this compared to NULL]
|
----- Forwarded message from Ruben Safir -----
Date: Tue, 15 Mar 2011 17:04:20 -0400 From: Ruben Safir To: Billy Cc: Ruben Safir Subject: Re: this compared to NULL User-Agent: Mutt/1.5.20 (2009-06-14)
On Tue, Mar 15, 2011 at 03:54:07PM -0400, Billy wrote: > On Tue, Mar 15, 2011 at 3:44 PM, Ruben Safir wrote: > > On Tue, Mar 15, 2011 at 01:06:56PM -0400, Billy wrote: > >> You're trying to return NULL from a method that returns MESSAGE. > >> > >> That's not going to work. > >> It has nothing to do with the comparison: this==NULL > >> This would be clear if you used newlines in your code. > >> > >> There's no great advantage to squishing a method onto one line, > >> and it makes diagnostics harder to pinpoint. > >> > > > > Yeah - I debugged it to that problem by doing exactly as you said and > > breaking it up on multiple lines. ?But now I'm perplexed as to the best > > solution. > > > > I think that this is best fixed using a cast in the LIST object and then > > I need to add a constructor for an integer for MESSAGES. > > > > I was going to see how the strings library does this and maybe emulate > > that. > > The 'this' pointer won't ever be NULL, unless you're doing something weird.
It can be, at least in this case. Specifically, the next NODE is defined as NULL in the linked list and at one point I do a look ahead
obj->next()->value();
On the last link, next_ is assigned NULL. When it looks for a value, if one isn't constructed, then it segfaults. The solution to this has been so far to just return NULL as a value if this is NULL
> How would the method even get called? By dereferencing a NULL pointer? > That's undefined behavior, and you don't have to support it. > You absolutely don't have to support the 'else' case. > There is a reason why it's hard to do: it doesn't make sense to do it. :) > > assert(this!=NULL) or something if you must, but don't return something > artificial. > > > There is another puzzle that is bothering me. ?I had a bug that the > > compiler didn't pick up and I don't know why. > > > > The method value originally ended with a semicolon, which is something > > only a class should do, and nothing complained and everything initially > > worked (I initially just yanked the declaration from the Class and > > forgot to remove the semicolon). ?I believe that becuse it is a template > > class that this error wasn't picked up, bt I'm not certain how this > > affected the original code. > > It didn't affect the code at all.. > A stray semicolon isn't illegal, even in global scope. >
Even if it is after the }
> > > Ruben > >> > >> On Tue, Mar 15, 2011 at 2:17 AM, Ruben Safir wrote: > >> > I just realized you don't have the MYSQL setup, but here is the compiler > >> > output > >> > > >> > || g++ ? -Wall -ggdb -I/usr/local/include/mysql > >> > -I/usr/local/include/mysql++ -c linklist.cpp > >> > || g++ ?-Wall -ggdb -I/usr/local/include/mysql > >> > -I/usr/local/include/mysql++ -c linklist_main.cpp > >> > || In file included from linklist_main.cpp:1: > >> > || linklist.h: In member function ?unk CHAINLIST::NODE::value() > >> > [with unk = MESSAGE]?: > >> > linklist.h|154| instantiated from ?void > >> > CHAINLIST::LIST::display(std::ostream&) [with unk = MESSAGE]? > >> > linklist_main.cpp|312| instantiated from here > >> > linklist.h|43| error: conversion from ?int? to non-scalar type ?MESSAGE? > >> > requested > >> > || make: *** [linklist_main.o] Error 1 > >> > > >> > > >> > On Tue, Mar 15, 2011 at 01:59:08AM -0400, Ruben Safir wrote: > >> >> Try to compile this. ?It seems to be telling me that I can't compare > >> >> this to NULL which it has done just fine with the string<> library > >> >> and otherwise. > >> >> > >> >> I'm at a loss to the problem. > >> >> > >> >> Ruben > >> >> -- > >> >> http://www.mrbrklyn.com - Interesting Stuff > >> >> http://www.nylxs.com - Leadership Development in Free Software > >> >> > >> >> So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world ?- RI Safir 1998 > >> >> > >> >> http://fairuse.nylxs.com ?DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > >> >> > >> >> "Yeah - I write Free Software...so SUE ME" > >> >> > >> >> "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." > >> >> > >> >> "> I'm an engineer. I choose the best tool for the job, politics be damned.< > >> >> You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. ?I guess you missed that one." > >> >> > >> >> ? Copyright for the Digital Millennium > >> > > >> > > >> > > >> > -- > >> > http://www.mrbrklyn.com - Interesting Stuff > >> > http://www.nylxs.com - Leadership Development in Free Software > >> > > >> > So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world ?- RI Safir 1998 > >> > > >> > http://fairuse.nylxs.com ?DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > >> > > >> > "Yeah - I write Free Software...so SUE ME" > >> > > >> > "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." > >> > > >> > "> I'm an engineer. I choose the best tool for the job, politics be damned.< > >> > You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. ?I guess you missed that one." > >> > > >> > ? Copyright for the Digital Millennium > >> > > >> > >> > >> > >> -- > >> ?n??uop ?ll?q > > > > -- > > http://www.mrbrklyn.com - Interesting Stuff > > http://www.nylxs.com - Leadership Development in Free Software > > > > So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world ?- RI Safir 1998 > > > > http://fairuse.nylxs.com ?DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > > > > "Yeah - I write Free Software...so SUE ME" > > > > "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." > > > > "> I'm an engineer. I choose the best tool for the job, politics be damned.< > > You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. ?I guess you missed that one." > > > > ? Copyright for the Digital Millennium > > > > > > -- > ?n??uop ?ll?q
-- http://www.mrbrklyn.com - Interesting Stuff http://www.nylxs.com - Leadership Development in Free Software
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
"Yeah - I write Free Software...so SUE ME"
"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."
"> I'm an engineer. I choose the best tool for the job, politics be damned.< You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."
? Copyright for the Digital Millennium
----- End forwarded message -----
|
|