learning dragonfly or C...

Chris Pressey cpressey at catseye.mine.nu
Fri Nov 12 10:10:51 PST 2004


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

> Matthew Dillon <dillon at 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






More information about the Kernel mailing list