Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!uxc.cso.uiuc.edu!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Short code to determine compiler's number of registers Message-ID: <18603@mimsy.UUCP> Date: 18 Jul 89 05:02:54 GMT References: <396@uop.uop.EDU> <225800197@uxe.cso.uiuc.edu> <579@targon.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 34 In article <579@targon.UUCP> andre@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@mimsy.umd.edu Path: uunet!mimsy!chris