| Re: Returning a dynamic character array based on input length |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.fortran · Group Profile
Author: nospamnospam Date: Sep 10, 2008 18:58
George McBane gvsu.edu> wrote:
> Richard Maine wrote:
>
>>
>> Yes. Heck, it wasnt too awfully long ago that Fortran had *NO* dynamic
>> allocation of any kind. Dynamic allocation wasn't standard in Fortran
>> until f90. Prior to that, some codes used nonstandard nonportable hacks
>> of various kinds.
...
> At the beginning you allocate one humongous array X, and
> put the array and an integer pointer to the "next available element"
> in common.
...
> The reason I'm writing this: this simple scheme IS portable.
> I've used it on a dozen architectures with almost as many
> Fortran compilers and it has never caused trouble. So for a limited
> class of needs, there was a portable way to do allocations.
Well, yes... I've seen and used schemes like that plenty of times in the
past. And I suppose it is dynamic in that you are dynamically
allocating space within the array to your different purposes. But at the
language level, it is static. There is just that one big array that you
statically allocated at first. If it isn;t big enough, you need to go
back and recompile with it bigger. Or if it is too big for the machine
in question, you need to make it smaller and recompile.
Unless, of course, you used some different scheme to dynamically
allocate that big array. There are variants like that, where the one big
array is dynamically allocated using some nonportable means. But the
nonportable means is restricted to that one array, which does help keep
the portability issues under control. Once you've managed to allocate
the one array somehow or other, then you use schemes like the one you
mentioned (or more complicated variants that can handle more than just a
stack structure) to apportion the space within the array.
I'm assuming you didn't dynamically allocate the big array because you
didn't mention anything about that. If you did, that part must have had
some portability issues. I've seen lots of different ways to hack that.
One of the ones much used in "old times" was to put that one array in
blank common and count on being able to exceed its declared bounds to
get at memory that wasn't otherwise being used.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|