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: Chris Pressey <cpressey@xxxxxxxxxxxxxxx>
Date: Fri, 12 Nov 2004 10:11:42 -0800

On Fri, 12 Nov 2004 01:28:46 +0100 CET
"Jonas Sundström" <jonas@xxxxxxxxxxx> wrote:

> Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx> 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




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