May too many register variables hurt?
Doug Gwyn
gwyn at smoke.brl.mil
Sun Nov 25 06:05:49 AEST 1990
In article <972 at mwtech.UUCP> martin at mwtech.UUCP (Martin Weitzel) writes:
> ... only the first few of such declarations are effective ...
Clearly what was meant by this is that only the first few OF THOSE CURRENTLY
IN SCOPE are effective. Out-of-scope declarations are simply irrelevant.
As you note, the programmer has a hard time indicating which variables
are most important to registerize, when a variety of compilation
environments must be accommodated. What some developers have done is
to add a batch of macros in their system-configuration header:
/* Prioritized "register" declarations: */
#define REG_0 register
#define REG_1 register /* last available for 6809 */
#define REG_2 register /* last available for PDP-11 */
#define REG_3 /* nothing */
#define REG_4 /* nothing */
and in the application use these in a mutually-exclusive manner:
func() {
REG_2 int i;
REG_0 char *p;
...
{
REG_1 char *q;
REG_3 int j;
...
}
}
so that no more "register" storage-class specifiers are seen by the
compiler in any scope than are actually effective for the implementation.
I don't use this method myself, preferring to use "register" as a hint
rather than a requirement, but if you are hyper-concerned about this
level of optimization you might want to consider such an approach.
More information about the Comp.lang.c
mailing list