Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!mts.ucs.UAlberta.CA!Al_Dunbar From: userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) Newsgroups: comp.lang.c Subject: Re: Just a little something that has been bothering me. Message-ID: <2001@mts.ucs.UAlberta.CA> Date: 11 Dec 90 05:16:04 GMT References: <2753F21B.2F6@tct.uucp> <1990Nov30.180913.20890@clear.com> <1990Dec08.222943.1581@cs.widener.edu> Organization: MTS Univ of Alberta Lines: 37 In article <1990Dec08.222943.1581@cs.widener.edu>, sven@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@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 -------------------+-------------------------------------------