MESSAGE
DATE | 2004-09-10 |
FROM | Ruben Safir Secretary NYLXS
|
SUBJECT | Re: [hangout] Re: two dimensional arrays passed to functions
|
> Functions should be kept > clean enough that it isn't a problem. So abusing goto is > very bad, but so is abusing any other feature. I know > that when I use it, it's as a sort of last resort when > the alternatives would be worse (read: more bug-prone). >
Like longjump and short jump for errors?
> > You mean that give Oracle a function pointer to use in case of > emergency? That's a good idea. I think TCL does that, too.
Something like that. It's been a while, but I think it has it's own signal that will longjump to a named function.
> > > In addition, there is always signals, which is how I originally > handled > > errors. The thing is here, the 'error' is not necessarily an error. > It > > could be a normal response from the database, like an attempt to > insert > > already entered data on a unique key. In which case, I want to > switch > > over and do an UPDATE instead. > > Sound thinking. You're talking about gtk signals or Unix signals?
I meant unix signals, singnals.h I think in the C library. Also, consider GTK, in their obsession to force an Object-like notation onto everything, one of the benifits is that instead of capturing the whole of a structured program in if statements, you should be able to emit a GTk signal to the top level window, or carry the error handling up the tree, which already exists, without the need for break break break.
> > > > You were doing a return if anything went wrong, > > > and you never cleaned up the MYSQL session, so I suppose you > didn't > > > see a need for the goto before. > > > > Yeah, it is not apparent yet from the code, but the MYSQL struct > > instance, there is a flag called reconnect which I want to check > for. I > > believe if it is 1, then you need to reconnect. I actually want to > make > > that data structure global and to cache the database connection, > > eventually closing it in the destructor. > > Make a big struct (of which the MYSQL connection is one member) and > pass > it around everywhere. Much cleaner than using globals...
That's a thought but the last time I did that I had to malloc the structure and I really don't know where to free it since it is being used in all the lower Widgets. Otherwise it disapears from the tact. That's why, just for exepedency, I created those dreadful global structures to store data. You can't just create a structure and then passing to the callback function at g_pointer a because it disapears from the darn stack. It took me two days to figure that out this time, and a week last time (although RMS figured it out in about 15 seconds in the debugger.)
The wild factor here is that gtk_main() is actually interceeding in everything here. Roughly speaking, when you click on a button, your talking to gtk_main() which 'senses' the clicked event and then looks for the proper callback and then runs it. In this case at least, it is a darn mine field.
> > > I don't know what mysql_init(&MYSQL) does, but it does not allocate > any > > memory. > > One thing it does is allocates space for a MYSQL if you pass it a > NULL. >
Say again? Where did you read that? Then why did I have to make sure the memory was allowed for it? What the heck does mysql_init() do then. It completely didn't work otherwise. I'm totally confused now.
> >That is the reason for the assignment of the pointer. > > > I hope I'm missing something of the MYSQL API, because otherwise I > might > > end up creating a global flagging system in order to cache the > database > > connection. > > Go for it. But not global define a struct. You'll be happy you did. >
I need some rest. I feel like I'm back in College again. I've crammed for finals relearning 2 dimensional arrays, array function parameters, the string library, the mysql C API, the GTK C API, patch, diff, vi advanced features gdb, and C macros all in the last 48 hours, in addition to trying to remain with a sane program design and boning up on integration for Biopharmacuetics all in the last 48 hours. SOMEBODY better be giving me a masters degree when this is done.
Ruben ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|