[net.lang.f77] Question on "Parameter" statement; and a new question!

peters@cubsvax.UUCP (Peter S. Shenkin) (01/30/86)

In article <utah-cs.3651> donn@utah-cs.UUCP (Donn Seeley) writes:
>Peter Shenkin asks why
>
>	parameter (size = 10)
>	character*size string
>
>doesn't work.
> 		    .....
>				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.....
>
>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

OK, so I tried it the way you wrote it.  Now it runs just fine under VMS,
but under ULTRIX (presumably the 4.2bsd f77 compiler) it bombs out, but
only because it thinks "size" is a REAL;  "isize" works just fine.  So a
new question:  I always thought PARAMETER definitions were not subject to
the IMPLICIT rules;  VMS Fortran behaves according to my preconception, at 
least in this example.  So am I wrong, or is this YAf77B* ?

Peter S. Shenkin,  Columbia Univ. Biol. Sciences, NY, NY
{philabs,rna}!cubsvax!peters		cubsvax!peters@columbia.ARPA

* (Yet Another f77 Bug.)

ark@alice.UucP (Andrew Koenig) (01/31/86)

> OK, so I tried it the way you wrote it.  Now it runs just fine under VMS,
> but under ULTRIX (presumably the 4.2bsd f77 compiler) it bombs out, but
> only because it thinks "size" is a REAL;  "isize" works just fine.  So a
> new question:  I always thought PARAMETER definitions were not subject to
> the IMPLICIT rules;  VMS Fortran behaves according to my preconception, at 
> least in this example.  So am I wrong, or is this YAf77B* ?

The type of an identifier defined in a PARAMETER statement is determined
in exactly the same way as the type of any other identifier.  From
the Standard, page 8-8, lined 53ff:

	If a symbolic name of a constant is not of default
	implied type, its type must be specified by a type-statement
	or IMPLICIT statement prior to its first appearance in a
	PARAMETER statement.

Thus, you should have written:

	integer size
	parameter (size = 10)
	character * (size) string

(Sorry I neglected this on my previous posting.)

donn@utah-cs.UUCP (Donn Seeley) (01/31/86)

Peter Shenkin's new question:

	... I always thought PARAMETER definitions were not subject to
	the IMPLICIT rules; VMS Fortran behaves according to my
	preconception, at least in this example.  So am I wrong, or is
	[it a bug that Unix f77 makes PARAMETER constants have implicit
	types] ?

I don't have a copy of VMS Fortran to play with, but I believe you'll
find that both VMS Fortran and Unix f77 give implicit types to
PARAMETER constants, except for those constants whose names are
declared in explicit type statements.  Section 8.6 of the standard
says:  'If a symbolic name of a constant is not of default implied
type, its type must be specified by a type-statement or IMPLICIT
statement prior to its first appearance in a PARAMETER statement.' In
particular, 'Each [symbolic name] becomes defined with the value
determined from the expression ... that appears on the right of the
equals, in accordance with the rules for assignment statements...' I
was aware of this when I posted the article to which Peter Shenkin is
replying, but (sigh) I forgot to point it out, and I should have, since
it is very easy to overlook.  Thus a more complete example is:

	integer size
	parameter (size = 10)
	character*(size) string

So why does VMS Fortran accept the example without an integer type
declaration for 'size'?  Well, I imagine it simply converts 'size' to
integer type before using it as a length, another extension to the
standard among the many it contains.

Donn Seeley    University of Utah CS Dept    donn@utah-cs.arpa

schuh@geowhiz.UUCP (David Schuh) (01/31/86)

In article <413@cubsvax.UUCP> peters@cubsvax.UUCP (Peter S. Shenkin) writes:
>In article <utah-cs.3651> donn@utah-cs.UUCP (Donn Seeley) writes:
>>Peter Shenkin asks why
>>
>>	parameter (size = 10)
>>	character*size string
>
>OK, so I tried it the way you wrote it.  Now it runs just fine under VMS,
>but under ULTRIX (presumably the 4.2bsd f77 compiler) it bombs out, but
>only because it thinks "size" is a REAL;  "isize" works just fine.  So a
>new question:  I always thought PARAMETER definitions were not subject to
>the IMPLICIT rules;  VMS Fortran behaves according to my preconception, at 
>least in this example.  So am I wrong, or is this YAf77B* ?
>
>Peter S. Shenkin,  Columbia Univ. Biol. Sciences, NY, NY
>{philabs,rna}!cubsvax!peters		cubsvax!peters@columbia.ARPA

Peter,
	I believe that even Parameter arguments must be previously,
or implicitly declared.  I bet if you put the statement 
IMPLICIT LOGICAL(a,z)
before your parameter statement the compiler wouldnt like any of them.
Actually this is a good idea (implicit something) maybe using complex
would be even better, it makes misspellings etc easier to find, and
is something I use in all of my progs. notice however it must appear
in every subroutine and function.  So to recap try
	   implicit complex(orlogical)(a,z)
	   integer size
	   parameter (size = 10)
	   etc...
hope this helps
(and is right)
dave schuh
uwisc madison 
physics and geophysics depts.
!uwvax!geowhiz!schuh

garry@batcomputer.TN.CORNELL.EDU (Garry Wiegand) (02/04/86)

In a recent article donn@utah-cs.UUCP wrote:
>Peter Shenkin's new question:
>
>	... I always thought PARAMETER definitions were not subject to
>	the IMPLICIT rules; VMS Fortran behaves according to my
>	preconception, at least in this example. 
>...

I can help out a little, I think: There are TWO TYPES of "parameter"
statements in VMS Fortran!

If you use parentheses around the items in the list of parameters, the
compiler follows the Fortran-77 rules -- the "parameter" behaves almost
identically to the equivalent simple "data" statement. 

If you DON'T use parentheses, you get the old DEC Fortran-4-Plus
"parameter" definition -- the parameters work like simple small macros,
and the effective type of the parameter "name" is the type of the
expression on the right. 

If you think you may have fallen across this, try compiling with a
"/STANDARD" switch. 

(Hope you don't have too many ENDDOs or STRUCTUREs, or it will
complain loudly indeed.)

garry wiegand