🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

7 total messages Started by Peter S. Shenkin Mon, 27 Jan 1986 03:06
Question on "Parameter" statement
#300
Author: Peter S. Shenkin
Date: Mon, 27 Jan 1986 03:06
13 lines
1063 bytes
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
Re: Question on "Parameter" statement
#303
Author: Donn Seeley
Date: Wed, 29 Jan 1986 06:22
30 lines
1649 bytes
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
Re: Question on "Parameter" statement
#302
Author: Andrew Koenig
Date: Wed, 29 Jan 1986 17:03
36 lines
1468 bytes
> 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.
Re: Question on "Parameter" statement; and a new question!
#305
Author: Peter S. Shenkin
Date: Thu, 30 Jan 1986 01:47
32 lines
1882 bytes
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.)
Re: Question on "Parameter" statement
#308
Author: der Mouse
Date: Thu, 30 Jan 1986 11:05
29 lines
1756 bytes
> 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
Re: Question on "Parameter" statement; and a new question!
#307
Author: Donn Seeley
Date: Fri, 31 Jan 1986 01:08
32 lines
2155 bytes
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
Re: Question on "Parameter" statement; and a new question!
#309
Author: David Schuh
Date: Fri, 31 Jan 1986 04:25
36 lines
2171 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads