Re: learning dragonfly or C...

看板DFBSD_kernel作者時間21年前 (2004/11/13 02:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串21/23 (看更多)
On Fri, 12 Nov 2004 01:28:46 +0100 CET "Jonas Sundstr闣" <jonas@kirilla.com> wrote: > Matthew Dillon <dillon@apollo.backplane.com> wrote: > > :> struct fubar * blah; > > :> struct fubar *nblah; > > :> > > :> getmafubar(&nblah); > > :> blah = nblah; > ... > > Nope. Ok, I'll tell you... it's so the compiler can > > optimize 'blah' into a register. > > Cool discussion, though this a much later issue for > most coders, let alone those just starting to learn C. > > Random link: > http://c2.com/cgi/wiki?PrematureOptimization > > One part of programming that could use a lot more effort is writing > readable code, so that it actually makes sense to someone not familiar > with it. (Or one self, a week later.) Choosing descriptive names for > variables as opposed to names 1 or 2 chars long does a lot for > readability. (Not meant as criticism of any code shared here.) As a general principle, I agree with this completely; apropos to the above code, I don't think it's particularly hard to follow, but it does suffer the danger that, if someone doesn't know why two seemingly redundant struct fubar * variables are being used, they might be tempted to simplify the code by "refactoring" (ugh) one of them out. So, I'd definately prefer that this particular advanced C trick be commented when it appears. By some amazingly fortunate stroke of luck, the C language actually supports this comment intrinsically! To wit: struct fubar *blah; register struct fubar *reg_blah; :) -Chris
文章代碼(AID): #11bG6h00 (DFBSD_kernel)
討論串 (同標題文章)
文章代碼(AID): #11bG6h00 (DFBSD_kernel)