Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!phri!roy From: roy@phri.nyu.edu (Roy Smith) Newsgroups: comp.sys.mac.programmer Subject: Re: Pascal deficiency? Message-ID: <1990Dec17.233507.16372@phri.nyu.edu> Date: 17 Dec 90 23:35:07 GMT References: <1990Dec17.160242.5095@phri.nyu.edu> <1990Dec17.172613.7941@cs.umn.edu> Sender: news@phri.nyu.edu (News System) Organization: Public Health Research Institute, New York City Lines: 49 I asserted that: > in C, x++ and x=x+1 are absolutely and completely identical (as is x+=1). > Any decent compiler should generate exactly the same code for all three. sec@cs.umn.edu (Stephen E. Collins) replied: > Decent is the key word here. If your compiler does not optimize, you're > likely to get different code for these, and with the number of shoddy > software products on the market these days, you might want to investigate. My first impression of Stephen's posting was "well, any compiler that's so bad it can't generate code for x=x+1 as good as it does for x++ must really be the pits". So, I tried an experiment. I compiled: a () { int x; x = 1; x = x + 1; } b () { int x; x = 1; x++; } on my SunOS-3.5.2 system using the stock C compiler, with and without -O and compared the code generated with -S. I'll confess to never having learned the m68k instruction set, but it sure looks like in both cases, b() generated more efficient code than a(). Stripping away the function entry and exit code, basically you have: without -O flag with -O flag a() movl #0x1,a6@(-0x4) moveq #1,d0 movl a6@(-0x4),d0 movl d0,a6@(-4) addql #0x1,d0 addql #1,d0 movl d0,a6@(-0x4) movl d0,a6@(-4) b() movl #0x1,a6@(-0x4) moveq #1,d1 addql #0x1,a6@(-0x4) movl d1,a6@(-4) addql #1,a6@(-4) Clearly, either I was out of line making my original assertion or the stock SunOS-3.5.2 C compiler really is the pits! Maybe a little of both? Anyway, I'll still stand by my original assertion, that the -- and ++ operators are just syntactic sugar and the lack of them does not, by itself, make Pascal a worse language. It's not fair to heap the sins of poor compiler implementations on the language itself (unless there is something inherent in the language that makes it hard to write good compilers). As an afterthought, I would hope that the C compiler Sun is now unbundling and charging real money for would generate better code than the stock one they used to ship. -- Roy Smith, Public Health Research Institute 455 First Avenue, New York, NY 10016 roy@alanine.phri.nyu.edu -OR- {att,cmcl2,rutgers,hombre}!phri!roy "Arcane? Did you say arcane? It wouldn't be Unix if it wasn't arcane!"