DragonFly BSD
DragonFly kernel List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: learning dragonfly or C...


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 11 Nov 2004 14:04:48 -0800 (PST)

:
:>    This brings up an interesting ancillary issue in that you might also
:>    see a very experienced C programmer use a slightly different sort
:>    of construction, like this:
:>
:>    struct vnode *vp;
:>    struct vnode *nvp;
:>
:>    if ((error = ckpt_fhtovp(&vnh->vnh_fh, &nvp)) != 0)
:>	    return error;
:>    vp = nvp;
:>    /* nvp ignored, vp used from here on */
:>
:>    Care to take a guess at why advanced C programmers use this construction
:>    instead of simply passing &vp ?
:>
:>					-Matt
:
:well not knowing what vnh_fh or ckpt_fhtovp is, sets me back a bit, but
:I'll guess:
:
:...need more info... 
:http://fxr.watson.org/fxr/source/sys/ckpt.h?v=DFBSD
:
:is it a buffer to throw out illegal file handles inherited by NFS?
:
:// George

    Nope.  Ignore the actual function names and ignore the function of
    the code, its irrelevant.  Just focus on the question:  Why is
    &nvp being passed to a function and then vp assigned to nvp when
    one could simply pass &vp to the function and get rid of nvp entirely?

    Let me modify the example a little:

	struct fubar *blah;
	struct fubar *nblah;

	getmafubar(&nblah);
	blah = nblah;

	blech = blah->this + blah->that - somefunction(blah);
	and_other_random_things_using(blah);

	blah blah blah...

    Ok, so, the question is, why would an advanced C programmer every
    want to create a separate variable to pass the address to a function
    and then simply assign the result back to the first variable and never
    use the second variable again?

					-Matt
					Matthew Dillon 
					<dillon@xxxxxxxxxxxxx>



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]