Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!apple!sun-barr!newstop!sun!sally!plocher From: plocher%sally@Sun.COM (John Plocher) Newsgroups: comp.lang.c Subject: Re: Short code to determine compiler's Message-ID: <116229@sun.Eng.Sun.COM> Date: 18 Jul 89 06:06:22 GMT References: <396@uop.uop.EDU> <225800197@uxe.cso.uiuc.edu> <579@targon.UUCP> Sender: news@sun.Eng.Sun.COM Reply-To: plocher@sun.UUCP (John Plocher) Organization: Sun Microsystems, Mountain View Lines: 24 >>>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!