Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site utah-cs.UUCP Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!utah-cs!4bsd-f77 From: 4bsd-f77@utah-cs.UUCP (4.2 BSD f77 bug reports) Newsgroups: net.lang.f77,net.bugs.4bsd Subject: [4bsd-f77 #39] Parentheses aren't allowed in certain declarations Message-ID: <4bsd-f77-39@utah-cs.UUCP> Date: Sat, 1-Sep-84 23:17:29 EDT Article-I.D.: utah-cs.4bsd-f77-39 Posted: Sat Sep 1 23:17:29 1984 Date-Received: Fri, 14-Sep-84 08:10:45 EDT Sender: donn@utah-cs.arpa Organization: University of Utah CS Dept Lines: 111 From: Donn Seeley Subject: Parentheses aren't allowed in certain declarations in f77 Index: usr.bin/f77/src/f77pass1/gram.expr 4.2BSD Description: The f77 standard permits the length specification of a CHARACTER variable in a declaration to be a constant expression, not just a constant, but the compiler doesn't allow it when the optimizer is on. Jerry Berkman found and fixed this bug. Repeat-By: Try to compile the following program with the optimizer on (program from Jerry Berkman): ---------------------------------------------------------------- c get syntax error: "length must be a positive integer constant" character str*( 5 ) str = 'hi there' print *, str end ---------------------------------------------------------------- The compiler complains and dies: ---------------------------------------------------------------- chdec.f: MAIN: Error on line 2 of chdec.f: Declaration error length must be a positive integer constant Error. No assembly. ---------------------------------------------------------------- Fix: The problem is the useless OPPAREN operator which gets generated for parenthesized expressions when the optimizer is on. I still haven't figured out why it is there, but it is clearly pointless in declarations so the following simple change to gram.expr turns it off: ---------------------------------------------------------------- *** /tmp/,RCSt1028940 Mon Aug 20 18:01:03 1984 --- gram.expr Sat Aug 4 21:28:00 1984 *************** *** 12,18 expr: uexpr | SLPAR expr SRPAR ! { if (optimflag) $$ = mkexpr(OPPAREN, $2, ENULL); else $$ = $2; } --- 26,32 ----- expr: uexpr | SLPAR expr SRPAR ! { if (optimflag && parstate != INDCL) $$ = mkexpr(OPPAREN, $2, ENULL); else $$ = $2; } ---------------------------------------------------------------- If you are annoyed by the lack of punctuation in f77's error message (as Jerry was), there is a fix for that, too. Make the following changes to dclerr() and execerr() in error.c: ---------------------------------------------------------------- *** /tmp/,RCSt1028948 Mon Aug 20 18:03:12 1984 --- error.c Mon Aug 20 17:57:43 1984 *************** *** 105,111 err(buff); } else ! errstr("Declaration error %s", s); } --- 117,123 ----- err(buff); } else ! errstr("Declaration error: %s", s); } *************** *** 115,121 { char buf1[100], buf2[100]; ! sprintf(buf1, "Execution error %s", s); sprintf(buf2, buf1, n); err(buf2); } --- 127,133 ----- { char buf1[100], buf2[100]; ! sprintf(buf1, "Execution error: %s", s); sprintf(buf2, buf1, n); err(buf2); } ---------------------------------------------------------------- Donn Seeley University of Utah CS Dept donn@utah-cs.arpa 40 46' 6"N 111 50' 34"W (801) 581-5668 decvax!utah-cs!donn