Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!orchid!rbutterworth From: rbutterworth@orchid.UUCP Newsgroups: comp.lang.c Subject: A simple solution to force evaluation order on non-ANSI compilers. Message-ID: <7172@orchid.UUCP> Date: Wed, 29-Apr-87 14:02:12 EDT Article-I.D.: orchid.7172 Posted: Wed Apr 29 14:02:12 1987 Date-Received: Thu, 30-Apr-87 06:42:53 EDT Distribution: comp Organization: U of Waterloo, Ontario Lines: 27 For those people that are justifiably concerned about order of evaluation of floating point expressions, and don't want the compiler to optimize the expression, and don't want to have to resort to asigning temporaries, there is a simple solution. Put the following function into your library: double evaluate(value) double value; { return value; } Then you can write your expressions as x = 42.000 + evaluate( evaluate(y*3) + evaluate(z+83.7) ); This will guarantee that "y" is multiplied by 3, and "z" is added to 83.7, and that the two results are added together, and that that result is added to 42. It of course doesn't guarantee anything about whether the "y*" or the "z+" will happen first. (I said this was simple, I didn't say it was efficient.) If you move your code to an ANSI compiler, you can scrap the evaluate() function, and get the efficiency back with #define evaluate(value) (+(value))