unary +

emjej at uokvax.UUCP emjej at uokvax.UUCP
Wed Mar 19 01:40:00 AEST 1986


/* Written 12:11 pm  Mar 11, 1986 by bright at dataioDataio.UUCP in net.lang.c */
One Answer [to the question why not require C compilers to honor parentheses
if the human takes the time to put the #$!#! things in]:
	Compilers frequently parse the expressions into an internal form
which is a binary tree. a+(b+c) would look like:

	  +
	 / \
	a   +
	   / \
	  b   c

Where are the parentheses? They're gone, they are only used in guiding
the parser as it builds the tree. Thus, the optimizer doesn't know where
the parentheses were. 
/* End of text from net.lang.c */

Eh?  It doesn't *need* to know where the parentheses were; the order of
operations is completely specified by the tree.  If the coder had written
a+b+c most parsers would turn it into (+ (+ a b) c), linearizing the
notation to save space.

Optimizers that reorder operations, especially on floating-point computation,
at best will induce some detectable error, such as overflow.  At worst, they
will cause loss of precision.  I doubt that conscientious numerical analysts
would ever use a language that permitted such finagling behind the programmer's
back.

						James Jones



More information about the Comp.lang.c mailing list