Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!elroy.jpl.nasa.gov!decwrl!mcnc!ecsgate!ecsvax!uncw!session From: session@uncw.UUCP (Zack C. Sessions) Newsgroups: comp.lang.c Subject: Re: Efficiency Question Message-ID: <1019@uncw.UUCP> Date: 26 Feb 91 18:19:48 GMT References: <4bmBqau00Uh_M0aHgb@andrew.cmu.edu> <1991Feb25.181434.6462@ux1.cso.uiuc.edu> <1991Feb26.042023.2097@grebyn.com> Organization: Univ. of North Carolina at Wilmington Lines: 44 ckp@grebyn.com (Checkpoint Technologies) writes: >rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes: >>Since C gives you the opportunity to condense statements, I was wondering >>what difference to the compiler these 'shortcuts' make. >> >> x = x + 1; can become >> x += 1; which can be further condensed to >> x++; >There's not much reason to use the first form, that I can see. Unless >you're a die-hard Fortran programmer. Ahh, but a perfectly valid statement, nonetheless, which means perfectly OK to use if you so desire. Therefore, the compiler must be capable of parsing the statement and generating opject code. Point is, does the compiler make an optimization pass at the source level or purely at the object level (or hopefully, both)? Depends on the compiler. The one I use on my PC doesn't as far as I know. I would hope C compilers implemented on university based systems would. >The second form as it stands has no real advantage over the third. See same comment above. >On the other hand, consider this fragment: >#define H_WIDTH 1 > int x; /* current horizontal position */ > /* I draw a (skinny) graphic figure of width H_WIDTH. Then: */ > x += H_WIDTH; /* move drawing pen by figure width */ <- versus > x++; >The first conveys more semantics to the reader. The second *may* be >faster. If so, that's tough luck, I still wouldn't use it. I might >even be willing to argue that the second is *incorrect* in this case. Irrelavent to the original question. Zack Sessions ...!ecsvax!uncw!session