Path: utzoo!utgpu!watmath!maytag!aries5!giguere From: giguere@aries5.uucp (Eric Giguere) Newsgroups: comp.lang.c Subject: Re: Short code to determine number of registers Message-ID: <309@maytag.waterloo.edu> Date: 18 Jul 89 05:04:59 GMT References: <396@uop.uop.EDU> <225800197@uxe.cso.uiuc.edu> <579@targon.UUCP> Sender: daemon@maytag.waterloo.edu Reply-To: giguere@aries5.waterloo.edu (Eric Giguere) Organization: Computer Systems Group, University of Waterloo Lines: 40 I for one am quite surprised that the various tests for register allocation posted over the last few days can be compiled by any compiler. In the case of ANSI compilers the following section applies: "... storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined." (3.5.1) to which the following (important!) footnote is added: "The implementation may treat any register declaration simply as an auto declaration. However, whether or not addressable storage is actually used, the address of any part of an object declared with storage-class specifier register may not be computed, either explicitly (by use of the unary & operator as discussed in 3.3.3.2) or implicitly (by converting an array name to a pointer as discussed in 3.2.2.1). Thus the only operator that can be applied to an array declared with storage-class specifier register is sizeof." So if I write main() { register int a, b, c, d, e, /* etc. */ x, y, z; int *ptr; ptr = &z; } the compiler should flag this as an error, whether or not the underlying architecture has 1, 2, 7, 15 or 26 registers available to be allocated. Probably the only way to determine the number of registers a compiler allocates is by disassembling the final object code. This method is quite portable :-) Eric Giguere 268 Phillip St #CL-46 For the curious: it's French ("jee-gair") Waterloo, Ontario N2L 6G9 Bitnet : GIGUERE at WATCSG (519) 746-6565 Internet: giguere@aries5.UWaterloo.ca "Nothing but urges from HELL!!"