Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!mcnc!duke!bet From: bet@orion.mc.duke.edu (Bennett Todd) Newsgroups: comp.lang.c Subject: Re: Short code to determine compiler's Message-ID: <15015@duke.cs.duke.edu> Date: 18 Jul 89 20:45:35 GMT References: <396@uop.uop.EDU> <225800197@uxe.cso.uiuc.edu> <579@targon.UUCP> Sender: news@duke.cs.duke.edu Reply-To: bet@orion.mc.duke.edu (Bennett Todd) Organization: Diagnostic Physics, Radiology, DUMC Lines: 93 In-reply-to: andre@targon.UUCP (andre) In article <579@targon.UUCP>, andre@targon (andre) writes: >/* test register usage of compiler */ > >main() >{ > register n1, n2, n3, n4, n5, n6, n7, n8; /* etc. */ > int *a; > > a = &n8; > a = &n7; > > /* repeat n6 - n2 */ > a = &n1; >} > >/* end */ Compilers are completely within their rights to give error messages for all these "®" expressions, whether or not they put any of them in registers. In fact, the "register" modifier is routinely ignored by both the stupidest and the smartest compilers; *very* *very* smart compilers could if they wished note ONLY that such variables may not have their address taken (a vaguely similar optimization hint to the unlamented "noalias"). In fact, as far as I know, the prohibition on taking the address of a variable flagged as "register" is the only language defined effect it has. Now, to check a specific, real compiler. Using gcc 1.34, I compiled the following: int main() { register n1, n2, n3, n4, n5, n6, n7, n8; /* etc. */ register n9, n10,n11,n12,n13,n14,n15,n16,n17; int *a; a = &n17; a = &n16; a = &n15; a = &n14; a = &n13; a = &n12; a = &n11; a = &n10; a = &n9; a = &n8; a = &n7; a = &n6; a = &n5; a = &n4; a = &n3; a = &n2; a = &n1; return(0); } Calling that file "junk.c" I then ran the command make junk.o >& output which, because of how I define CC and CFLAGS, produced this in "output" (manually edited to break the gcc command line in two): gcc -O -g -Wall -Wwrite-strings -msoft-float -fstrength-reduce \ -finline-functions -I/usr/local/include -c junk.c -o junk.o junk.c: In function main: junk.c:6: address of global register variable requested junk.c:7: address of global register variable requested junk.c:8: address of global register variable requested junk.c:9: address of global register variable requested junk.c:10: address of global register variable requested junk.c:11: address of global register variable requested junk.c:12: address of global register variable requested junk.c:13: address of global register variable requested junk.c:14: address of global register variable requested junk.c:15: address of global register variable requested junk.c:16: address of global register variable requested junk.c:17: address of global register variable requested junk.c:18: address of global register variable requested junk.c:19: address of global register variable requested junk.c:20: address of global register variable requested junk.c:21: address of global register variable requested junk.c:22: address of global register variable requested make: *** Error 1 Look, ma, 17 registers allocated for integers on a 68020! I would conclude that a teacher giving his students the assignment of determining how many register variables are actively supported by their compiler had better be teaching compiler internals, and not the C programming language. -Bennett bet@orion.mc.duke.edu