Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!swrinde!cs.utexas.edu!uunet!kddlab!ccut!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.co.jp (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: register variable??? Message-ID: <10826@riks.csl.sony.co.jp> Date: 13 Sep 89 02:45:17 GMT References: <30585@srcsip.UUCP> Reply-To: diamond@ws.sony.junet (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 40 In article <30585@srcsip.UUCP> sklee@srcsip.UUCP () writes: > i = 0; > while (i < 4) list[i] = list[++i]; > >... if I define "int i" instead of "register int i", >the result is [different] This question seems to come up twice a week now. list [ i ] = list [ ++ i ] [b] [a] [last] [4] [3] [2] [1] There are several possible sequences of evaluation. Operation [1] (fetching value of i) must precede [2] (increment). Operation [2] must precede [3] (array indexing) because it is a pre-increment operation. Operation [3] must precede [4] (fetching value of array element). Operation [a] (fetching value of i) must precede [b] (array indexing). All of the above must precede the assignment [last]. Notice what isn't specified? Does operation [a] come before or after operation [2]? [a] could even come before [1] or after [4]. On the right-hand side, the rules of the language specify that list[++i] uses the new value of i. On the left-hand side, the rules do not specify whether list[i] uses the old or new value of i. If you were lucky, the compiler would call a random number generator to decide whether to use the old value of i or the new value. Unfortunately it chose one way for "register" and the other way for non-"register". Therefore you were confused, and you thought that "register" makes a difference. It does not. -- -- Norman Diamond, Sony Corporation (diamond@ws.sony.junet) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.