From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,42dee056ce900ae6 X-Google-Attributes: gid103376,public From: dweller@news.imagin.net (David Weller) Subject: Re: C's register keyword Date: 1997/09/08 Message-ID: <5v1k1v$3mq6$1@prime.imagin.net>#1/1 X-Deja-AN: 270773194 References: <5uqhm2$t48$1@goanna.cs.rmit.edu.au> Organization: ImagiNet Communications Ltd, Arlington, Texas Newsgroups: comp.lang.ada Date: 1997-09-08T00:00:00+00:00 List-Id: In article , Tucker Taft wrote: >Tristan Ludowyk (ludowyk@yallara.cs.rmit.edu.au) wrote: >: is there an ada equivelent to 'register' in C/C++? > >In Ada 95, any local variable not declared "aliased" is a candidate >for living in a machine register. The compiler decides based >on usage. > As a modest, and perhaps slightly contrived example: C version: for (int i = 0; i < 10000; i++) for (int j = 0; j < 10000; j++) /*some nontrivial statement*/ Ada version: for i in 0..9999 loop for j in 0..9999 loop --some nontrivial statement end loop; end loop; Using gcc/GNAT, you find that the Ada executable yields faster performance (assuming same optimization levels and identical times for the "some nontrivial statement". Only when you declare the i and j variables in C as with the "register" keyword do you see identical performance. This is, IMHO, a fundamental point behind Ada -- the compiler can (and does!) perform several optimizations that would otherwise be impossible in C without "aggressive" programming (and considering that C requires the developer to program "defensively", it should come as no surprise that these highly skilled "aggressive-defensive" programmers also tend to be "manic-depressive" :-) As Tuck points out, "aliased" variables in Ada behave much like "un-registered" variables in C, but also have a LOT more "protection" to them than C variables. Of course, having nattered away like this, it all really boils down to the one mantra all programers should (and rarely) follow: Measure everything! -- Booch Components Homepage: www.rivatech.com ||Ada Homepage: www.adahome.com Microsoft: The gasoline-powered engine of the 21st century