Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decvax.UUCP Path: utzoo!linus!decvax!minow From: minow@decvax.UUCP (Martin Minow) Newsgroups: net.lang.c Subject: Re: ++ operator Message-ID: <312@decvax.UUCP> Date: Mon, 26-Dec-83 16:16:56 EST Article-I.D.: decvax.312 Posted: Mon Dec 26 16:16:56 1983 Date-Received: Tue, 27-Dec-83 03:07:51 EST References: <1092@mit-eddie.UUCP> Organization: DEC UNIX Engineering Group Lines: 36 Mark Plotnik asks for a "precise, consistent definition" of the semantics of ++ and -- (among other things). The definition is "compiler dependent", but all side effect operators will be evaluated when control passes to the next statement. (It may be the case that side-effect operations will be evaluated before passing over , && or ||, but I wouldn't bet on it. Vax-11 C (on VMS) is very willing to evaluate auto-increment operators at "unusual" times. For example, consider the following: int stack[123]; /* Evaluation stack */ int *stack_pointer = stack; #define push(x) (*--stack = x) /* Stuff into the stack */ #define pop() (*stack++) /* Get from the stack */ int eval(operator) { switch (operator) { ... case OP_ADD: push(pop() + pop()); ... You may think that "*--stack = *stack++ + *stack++;" will "do the right thing", but it is (by demonstration) compiler dependent. (I found that out the hard way -- the original had the misleading comment "don't need a temp variable since addition is commutative"). The correct expression of the above is: temp = pop(); temp += pop(); push(temp); Martin Minow decvax!minow