[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tpop3d-discuss]code questions
From: |
Chris Lightfoot |
Subject: |
Re: [tpop3d-discuss]code questions |
Date: |
Fri, 12 Mar 2004 13:13:29 +0000 |
User-agent: |
Mutt/1.3.24i |
On Fri, Mar 12, 2004 at 04:57:49AM -0800, Jeff Davis wrote:
>
> First I'd like to say I think the code is very good overall and very
> well commented. However, I'm kind of a newbie to actually working with
> other people's code (I am competent with C in most ways, but just not
> other peoples' C), and some things confused me.
>
> Example code in netloop.c fork_child:
> for (J = connections; J < connections + max_connections; ++J)
> if (*J && *J != c) {
> close((*J)->s);
> (*J)->s = -1;
> connection_delete(*J);
> *J = NULL;
> }
>
> Is that different from the more obvious solution (at least the obvious
> solution to me):
> for(i = 0; i < max_connections; ++i) {
> if ( connections[i] && connections[i] != c) {
> close(connections[i]->s);
> connections[i]->s = -1;
> connection_delete(connections[i]);
> connections[i] = NULL;
> }
> }
>
> It just kind of caught me off guard to see the pointer-arithmetic loop.
> I'm not challenging anything, but I'm trying to get some insight because
> I'm not very experienced with other peoples' code.
No, they're the same. IIRC that code exists in its
current form because originally the connections were held
in a linked list rather than an array, and therefore had
to be enumerated with pointers. That bit of code could
probably do with a cleanup.
> Some other minor things included the huge case statements and the short
> variable names (although I figured out the short names quickly enough).
> There are some global vars around that I'm not quite understanding yet,
> but I think those are necessary for the multi-process system.
-- not necessary, but convenient. Most of them cache
configuration options. The case statements aren't *that*
huge....
--
``Most photographers have learned the hard way that satisfactory
results cannot be obtained without loading the camera with film.''
(Philip Greenspun)