Re: learning dragonfly or C...

看板DFBSD_kernel作者時間21年前 (2004/11/12 06:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串10/23 (看更多)
: :> 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@backplane.com>
文章代碼(AID): #11a-Xc00 (DFBSD_kernel)
討論串 (同標題文章)
文章代碼(AID): #11a-Xc00 (DFBSD_kernel)