Short code to determine compiler's
John Plocher
plocher%sally at Sun.COM
Tue Jul 18 16:06:22 AEST 1989
>>>Some students here had to determine the number of registers (data
>>[ text explaining why this doesn't always work ]
>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 :-)
> [ code that relies on a compiler barfing on ®istervar ]
This fails if your compiler notes that you did a & of a register var and
removes the register modifier from the declaration for you. It also fails
if your compiler is nice enuf to make a temp var for you and copy the value
from a reg to that var so you can take the addr of it. I have seen compilers
that do both (the latter is only really doable in a data flow analyzing compiler
where modification points and aliasing can be taken into account).
There is no compiler/OS/CPU portable way to do this, but on a specific cpu
with a specific compiler it can be done. But if the CPU and compiler are already
known in that much detail, why determine this dynamically? Actually, what
is the use of this knowledge anyways? The new family* of compilers do a better
job of optimization if *they* can do the register declarations for you.
-John Plocher
* The non-pcc based compilers from Greenhills, The Free Software Foundation,
Silicon Valley Systems, Metaware and others all do a better job of speed
optimization if you do NOT specify explicit register variables!
More information about the Comp.lang.c
mailing list