register variable declaration question

Dave Jones djones at megatest.UUCP
Wed Nov 9 07:40:50 AEST 1988


>From article <624 at scotty.UUCP>, by jwr at scotty.UUCP (Dier Retlaw Semaj):
> 
> A question:
> 
> When should one declare a parameter to be a register variable?
> 

I can't tell you when you "should" declare a register parameter,
but I can give you an example of how I use them.

I write lot's of C routines which are in the "object-oriented" mold.
That is to say, they update only one kind of data-structure.
I name the structures ("classes", in the current jargon) with typenames
with capital letters.  If a routine-name begins with a capitol letter,
the reader knows theat it is tied to a class -- it is a "method"
of that class.  It's first parameter, named "obj",  will invariably be 
a pointer to a structure of the given type.  I usually declare that pointer
to be "register", because it will be dereferenced many times within
the procedure.

typedef struct
{
  type1 field1;
  type2 field2;
  /* etc. */
}Widget;


int
Widget_fiddle(obj, arg1, arg2)
   register Widget* obj;
   int arg1;
   int arg2;
{
  /* Fiddle with the widget. */

}



More information about the Comp.lang.c mailing list