Just a little something that has been bothering me.

Al Dunbar userAKDU at mts.ucs.UAlberta.CA
Tue Dec 11 16:16:04 AEST 1990


In article <1990Dec08.222943.1581 at cs.widener.edu>, sven at cs.widener.edu (Sven Heinicke) writes:
>What is quicker?
>
>        int a = 0,i = 0;
>
>or
>
>        int a,i;
>        i = a = 0;
>
>and why?
>
>This type of thing has been bothering me for a long time.
>
>--
>sven at cs.widener.edu                                      Widener System Manager
 
The correct answer to the first question is "the one that takes
less time to execute". At least that is about all that can be
said until you say what compiler you are using. Once you've said
that, the answer can be further refined by using a stopwatch.
 
Since the first question cannot be answered, neither can the
second, except to say "because it takes less time to execute".
 
having said the above, a simple compiler *might* generate quicker
code for the second case, because once the zero value is
generated in a register to assign to a, it needn't be generated
again. I believe, however, that most compilers worth the diskette
they are sold on would optimize these fragments into identical
code.
 
-------------------+-------------------------------------------
Al Dunbar          |
Edmonton, Alberta  |  "this mind left intentionally blank"
CANADA             |          - Manuel Writer
-------------------+-------------------------------------------



More information about the Comp.lang.c mailing list