Path: utzoo!attcan!uunet!know!sdd.hp.com!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!srcsip!msi.umn.edu!cs.umn.edu!uc!shamash!hare!ddh From: ddh@hare.cdc.com (Dan Horsfall) Newsgroups: comp.lang.fortran Subject: Re: passing DIMs via COMMON?? Message-ID: <26872@shamash.cdc.com> Date: 11 Oct 90 14:26:26 GMT References: Sender: news@shamash.cdc.com Reply-To: ddh@dash.udev.cdc.com (Dan Horsfall) Distribution: comp Organization: Control Data Corp, Arden Hills, MN Lines: 71 In article burley@world.std.com (James C Burley) writes: > In article 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. --