Path: utzoo!attcan!uunet!husc6!purdue!i.cc.purdue.edu!h.cc.purdue.edu!ags From: ags@h.cc.purdue.edu (Dave Seaman) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <3974@h.cc.purdue.edu> Date: 15 Sep 88 16:44:38 GMT References: <893@amelia.nas.nasa.gov> <3064@lanl.gov> <820@cernvax.UUCP> <406@quintus.UUCP> Reply-To: ags@h.cc.purdue.edu.UUCP (Dave Seaman) Organization: Purdue University Lines: 40 In article <406@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: [ explaining that a particular expression is not ambiguous in C ] >In fact, this is one of the reasons why some C programmers resent the >Fortran people telling them what to do with parentheses: C programmers >are used to adding parentheses to expressions to clarify the grouping >*without* changing the semantics. The point at issue is whether > I = N * P * Q; >and I = (N * P) * Q; >have the same meaning. In pre-ANSI C, they did; a compiler could >rearrange both. In the current draft, the two expressions are different, >exactly as in Fortran. What are you afraid of? What problem does it cause if the compiler decides to respect the extra parentheses that you put in for no reason? After all, even in C under the K&R standard, there is no guarantee that the compiler will NOT treat the expression differently because of the parentheses. If all you are interested in is emphasizing grouping for the benefit of the human reader, you can do that quite effectively by the proper use of white space. You don't need parentheses. In fact, white space works BETTER than parentheses for this purpose. Compare: t = a*cos(x) + b*cos(y) + c*f(x-y) + d*f(x+y) with t=((a*cos(x))+(b*cos(y)))+((c*f(x-y))+(d*f(x+y))) -- which would you rather read? In the expression "(A*B)*C", suppose A and C are large enough that the product causes overflow, while B is small enough that the expression can be evaluated sensibly, provided the compiler does not rearrange it to "(A*C)*B". I think the programmer has good reason to complain if his parentheses are not respected in this situation. In short, respecting parentheses has no bad effects, and not respecting them can be downright harmful. -- Dave Seaman ags@j.cc.purdue.edu