martin@slsiris.harvard.edu (Mr. Science) (10/09/90)
Hi... Ive noticed that when I try to specify LUNs or adjustable array parameters by passing the value in a common block, f77 doesnt know what to do. For example, I want to specify all "magic numbers" (LUNs, array DIMs...) in the main program section to simplify code maintenance. If I try to pass array dimensions via a common block, the compiler complains about an "adjustable array dimension error"; if I pass these values in the subroutine call, however, the program executes as expected. To simplify the code, I would prefer not passing these values for each subroutine call. Of course, I can solve my problem by putting these parameters in an include file; I was just curious about the difference in passing mechanisms between variables in a common block and variables in a subroutine call. ...pkm Patrick Martin -- .................................................................... Patrick Martin Martin@SLSVAX.Harvard.Edu Martin@SLSIRIS.Harvard.Edu Disclaimer: I get taxed too high to afford an opinion. ....................................................................
burley@world.std.com (James C Burley) (10/11/90)
In article <MARTIN.90Oct9111140@slsiris.harvard.edu> martin@slsiris.harvard.edu (Mr. Science) writes:
Ive noticed that when I try to specify LUNs or adjustable array
parameters by passing the value in a common block, f77 doesnt know
what to do. For example, I want to specify all "magic numbers"
(LUNs, array DIMs...) in the main program section to simplify code
maintenance. If I try to pass array dimensions via a common block, the
compiler complains about an "adjustable array dimension error";
if I pass these values in the subroutine call, however, the program
executes as expected. To simplify the code, I would prefer not
passing these values for each subroutine call.
....................................................................
Patrick Martin
Martin@SLSVAX.Harvard.Edu
Martin@SLSIRIS.Harvard.Edu
Disclaimer: I get taxed too high to afford an opinion.
....................................................................
Could you post a reduced example of what you're trying to do with LUNs or
arrays that isn't working? Meanwhile, I tried sending you an answer twice
but some mail daemon rejected it, so here is my attempt to address the
array issue:
Make sure you are passing the arrays themselves as dummies; you can
not put adjustable arrays in common areas.
However, if you are doing this right, and the compiler accepts a subroutine
whose dummy arguments include not only an adjustable array but all the
variables that dimension the array, but does not accept a subroutine
where some or all of the variables that dimension a dummy array are in
a common area known to the subroutine, then I think the compiler is
broken.
I.e. you should be able to do both
SUBROUTINE X(A,N)
INTEGER A(N)
...
and
SUBROUTINE X(A)
INTEGER A(N)
COMMON /FOO/N
...
This is, I believe, standard for ANSI 77.
Whether a particular implementation (such as f77) supports it is another
issue!
James Craig Burley, Software Craftsperson burley@world.std.com
ddh@hare.cdc.com (Dan Horsfall) (10/11/90)
In article <BURLEY.90Oct11030305@world.std.com> burley@world.std.com (James C Burley) writes: > In article <MARTIN.90Oct9111140@slsiris.harvard.edu> martin@slsiris.harvard.edu (Mr. Science) writes: > > Ive noticed that when I try to specify LUNs or adjustable array > parameters by passing the value in a common block, f77 doesnt know > [ ... ] > .................................................................... > Patrick Martin > > > Make sure you are passing the arrays themselves as dummies; you can > not put adjustable arrays in common areas. Yes, this is the essence of the problem > > However, if you are doing this right, ... then I think the compiler is > broken. > > I.e. you should be able to do both > SUBROUTINE X(A,N) > INTEGER A(N) > ... > > and > > SUBROUTINE X(A) > INTEGER A(N) > COMMON /FOO/N > ... > > This is, I believe, standard for ANSI 77. Technically, the second form IS permitted, but it is a rarely used form. In my experience, I've never seen it (and had to look it up in the standard to write this). Given its low use, I'd hesitate to depend on it in case a particular implementation hasn't done a foolproof job. > > Whether a particular implementation (such as f77) supports it is another > issue! Absolutely! Other tricks that have been used in the past are to declare the array in a common block to have length 1 (or some other small value, read on) in all routines except the Main. At some point, however, the actual amount of space actually needed must be allocated, and when using COMMON, you have to use COMMON to do so (No, that's not the department of redundancy department -- it means you can't fake out COMMON with other forms of dynamic allocation.) If your arrays are one-dimensional, you caan pass them through arglists and declare them with DIMENSION A(*) in all routines _except_ the main, since, again, somebody somewhere has to allocate the actual amount of space needed. Here, unlike COMMON, you may allocate this space in some other fashion, and pass its address thru the arglist of each subprogram that needs the array. If you need higher order arrays, only the last dimension can float in this manner, but this is still an adequate solution for some problems. If you have further questions on this issue, contact me directly and we'll talk. I don't describe myself as "the walking flint", but in my current position I write FORTRAN (dialect) translators in FORTRAN and consider myself pretty well versed in the predominate extension and implementation dependencies. In case Pnews botches my sig, I'm ddh@dash.udev.cdc.com. --
ndeng@euler.Berkeley.EDU (10/12/90)
In article <BURLEY.90Oct11030305@world.std.com> burley@world.std.com (James C Burley) writes: >In article <MARTIN.90Oct9111140@slsiris.harvard.edu> martin@slsiris.harvard.edu (Mr. Science) writes: [stuff deleted] > SUBROUTINE X(A) > INTEGER A(N) > COMMON /FOO/N > ... SOme compliers will break for the above. But my experience is, if you change the sequence of INTEGER and COMMON statements, most compiler will accept it. The following works everytime to me: subroutine x(a) common /foo/ n integer a(n) ... Of course, you need to specify the value of the variable n before this subroutine is called. >This is, I believe, standard for ANSI 77. > >Whether a particular implementation (such as f77) supports it is another >issue! > >James Craig Burley, Software Craftsperson burley@world.std.com