Short code to determine compiler's number of registers
Chris Torek
chris at mimsy.UUCP
Tue Jul 18 15:02:54 AEST 1989
In article <579 at targon.UUCP> andre at targon.UUCP (andre) writes:
>Yes, I think you can write a program that checks the nr of registers,
>but you will get the answer at compile time, not run time :-)
>
>the program [takes the address of variables declared with the `register'
keyword]
>The compiler will assing n1 to n{x} to the registers it has available and
>the rest will be normal variables. You can take the address of a variable
>but not of a register, so the compiler will start to complain at the first
>line that tries to take the address of a register. That's why the a = &n{x};
>lines must count backwards.
The first statement is false. The first part of the second statement is
true. The second part of the second statement is false.
A compiler is free to assign variables to registers without regard to
the `register' keyword. The programmer is required not to attempt to
use the `&' address-of operator on any variables declared with the
`register' keyword. That is, you cannot take the address of a register
variable, whether or not it is in fact in a machine register.
The real problem here is that the compiler is free to use none, any or
all machine registers whenever it wants; it is possible (if stupid) for
a compiler to switch from `none' to `all' simply because the code was
compiled in the afternoon rather than the morning.
That said, the way to find out how many registers the compiler will
use on your code is to compile your code and count how many registers
were used. This is completely reliable, although not necessarily
repeatable. It is also likely to be a useless statistic.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list