Some subsurface notes from a week of diving

Dirk Hohndel dirk at hohndel.org
Mon Mar 17 09:56:13 PDT 2014


On Mon, 2014-03-17 at 08:31 -0700, Linus Torvalds wrote:
> On Mon, Mar 17, 2014 at 8:13 AM, Dirk Hohndel <dirk at hohndel.org> wrote:
> >
> > Look at this little gem. I think I'll reorder this a little bit:
> 
> No need.
> 
> > +static inline int number_of_computers(struct dive *dive)
> > +{
> > +       int total_number = 0;
> > +       struct divecomputer *dc = &dive->dc;
> > +
> > +       if (!dive)
> > +               return 1;
> >
> > (hint: think what happens if dive == null)
> 
> Absolutely nothing happens.
> 
> It does not *access* the dive pointer. It just creates a new pointer
> *offset* from the dive pointer.
> 
> Doing "&ptr->xyz" is just pointer arithmetic. It may syntactically
> look like an access due to the "->", but it really isn't. It literally
> means "calculate the address of the field xyz in the structure pointed
> to by ptr".

Some days I hate the details of pointer arithmetic. I guess you are
right.
I reordered it anyway because otherwise I'll stumble across it next time
I look at it :-)

/D



More information about the subsurface mailing list