Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!portal!sv!news From: leonardr@svc.portal.com (Leonard Rosenthol) Newsgroups: comp.sys.mac.programmer Subject: Re: Increment (Was Re: Pascal deficiency)? Message-ID: <1990Dec18.192816.6645@svc.portal.com> Date: 18 Dec 90 19:28:16 GMT References: <1990Dec18.001753.3756@Neon.Stanford.EDU> <1990Dec18.004838.5623@Neon.Stanford.EDU> <1990Dec18.015258.8631@Neon.Stanford.EDU> Sender: news@svc.portal.com Reply-To: leonardr@svc.portal.com (Leonard Rosenthol) Organization: Software Ventures Corporation. Lines: 42 In article <1990Dec18.015258.8631@Neon.Stanford.EDU>, kaufman@Neon.Stanford.EDU (Marc T. Kaufman) writes: In article <1990Dec18.015258.8631@Neon.Stanford.EDU>, you write: > Well, to generate the above code, I declared 'external int i'. The C > compiler DOES put things in registers. However, MPW C still generates > pretty crufty code for i = i+1: > > MOVE.L D2,D0 > ADDQ.L #$1,D0 > MOVE.L D0,D2 > > and this is with optimization ON! > Just out of curiosity, I tried this experiment on our handy UNIX box (which unfortunately is a NeXT running system 2.0) running gcc -O (GNU v1.36/NeXT v3.11) and using the routines: alpha() { int i; i = 1; i = i +1;} beta() { int i; i = 1; i++;} main() {alpha(); beta()} And it generated the following: link fp, #0 unlk fp rts If a return(i) was added to both alpha and beta, then they both generate: link fp, #0 moveq #2, d0 unlk fp rts Seems like a REAL nice optimization, eh?!? Oh, it should be pointed out that the debugger (gdb) requires the link/unlk instructions, and it may be possible to even have THEM optimized out. -- ---------------------------------------------------------------------- + Leonard Rosenthol | Internet: leonardr@sv.portal.com + + Software Ventures | GEnie: MACgician + + MicroPhone II Development Team | AOL: MACgician1 + ----------------------------------------------------------------------