peters@cubsvax.UUCP (Peter S. Shenkin) (01/27/86)
The following construction doesn't work (compile-time error) in either ULTRIX f77 or VMS Fortran (on a Microvax). Should it work? Does it work on any machine/compiler you know of? Does the f77 standard say anything about this? PARAMETER ( Size = 10 ) CHARACTER * Size string ... etc. Cheers, Peter S. Shenkin, Dept. of Biol. Sci., Columbia Univ., NY, NY {philabs,rna}!cubsvax!peters cubsvax!peters@columbia.ARPA
donn@utah-cs.UUCP (Donn Seeley) (01/29/86)
Peter Shenkin asks why parameter (size = 10) character*size string doesn't work. The problem probably seems straightforward to those who have programmed in antique Fortrans... It is perhaps more obvious if one uses antique style: PARAMETER(SIZE=10) CHARACTER*SIZESTRING White space is not significant in Fortran, so SIZESTRING appears as one token to the Fortran compiler. This is obviously a syntax error since SIZESTRING is not defined and in any case no variable is being declared by the type statement. What was intended was probably: parameter (size = 10) character*(size) string My reading of the standard indicates that only integer constants (and not symbolic names of integer constants) may appear naked as length specifications; all other integer constant expressions must appear enclosed in parentheses (Section 8.4.2, ANSI X3.9-1978). This conveniently rules out the tokenizing difficulty described here... ISNTFORTRANWONDERFUL, 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
ark@alice.UucP (Andrew Koenig) (01/29/86)
> The following construction doesn't work (compile-time error) in either > ULTRIX f77 or VMS Fortran (on a Microvax). Should it work? Does it > work on any machine/compiler you know of? Does the f77 standard say > anything about this? > > PARAMETER ( Size = 10 ) > > CHARACTER * Size string You have to write CHARACTER * (Size) string From The Fortran 77 standard, page 8-6, lines 25ff: [the length is] (1) An unsigned, nonzero, integer constant (2) An integer constant expression (6.1.3.1) enclosed in parentheses and with a positive value (3) An asterisk in parentheses, (*) The parentheses are necessary to avoid ambiguity. Consider parameter (x = 1, xy = 2) character * xy z Remember that spaces are irrelevant in Fortran. Now: is this last statement to be interpreted as written or as: character * x yz ? Both are valid and there's no way to tell.
mouse@mcgill-vision.UUCP (der Mouse) (01/30/86)
> The following construction doesn't work (compile-time error) in either > ULTRIX f77 or VMS Fortran (on a Microvax). Should it work? Does it > work on any machine/compiler you know of? Does the f77 standard say > anything about this? > PARAMETER ( Size = 10 ) > CHARACTER * Size string > Peter S. Shenkin, Dept. of Biol. Sci., Columbia Univ., NY, NY > {philabs,rna}!cubsvax!peters cubsvax!peters@columbia.ARPA As I recall VMS FORTRAN (it's been a looong time), this would work if you wrote it PARAMETER size = 10 CHARACTER * (size) string I think you could put the parens in the PARAMETER statement with no ill effects, but the parens around the "size" after the star are necessary when the value there is a compile-time constant expression but not a plain constant. -- der Mouse USA: {ihnp4,decvax,akgua,etc}!utcsri!mcgill-vision!mouse philabs!micomvax!musocs!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse mcvax!seismo!cmcl2!philabs!micomvax!musocs!mcgill-vision!mouse Hacker: One who accidentally destroys / Wizard: One who recovers it afterward