Efficiency Question

Zack C. Sessions session at uncw.UUCP
Wed Feb 27 05:19:48 AEST 1991


ckp at grebyn.com (Checkpoint Technologies) writes:

>rg2c+ at 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



More information about the Comp.lang.c mailing list