Function pointer array crashing

I went back a little before f90 to the August 1988 draft of fortran 8x. It had two specific intrinsic functions, ESIZE(ARRAY,DIM) and DSIZE(ARRAY,DIM), that operated on real and double precision arrays. In both cases, the DIM argument was optional. Otherwise, these proposed functions worked the way that SIZE() was eventually defined in f90. I guess it did not occur to anyone at that time that it might be useful to have a SIZE() function that worked on integer, logical, complex, character, or derived type arrays? As noted above, the f90 version of SIZE() was generic.

I also noticed an error in the gfortran documentation. It states that SIZE() was added in f95, and then revised in f2003 to add the KIND optional argument. That last part is correct, but the f95 part is incorrect, it was an f90 function.

[ A single word was removed here because someone found it inappropriate. I personally donā€™t think it was not appropriate, given the context - but whatever. However the rest of this post should remain intact. If not, I see no reason to keep posting in this forum, because I will never ever tolerate censorship. ]

And I actually remember you now from another topic where you had the exact same blatantly offensive stance. Ok man, have it your way. Iā€™m going to note your name this time, so that I wonā€™t bother again in the future.

I didnā€™t propagate any misinformation. Compilers did as I said. And I apologized for the fact I assumed they still do the same.

Indeed, it was a Fortran 90 function. I donā€™t think it was changed in Fortran 95 at all. The change happened when we ā€œcommon mortalsā€ had finally access to Fortran 2003.

Not really relevant to the original question, but I was curious if the size intrinsic was available in f2c as an F8X extension. It was (is) not.

C test.f
C intrinsic sin statement recognized
      intrinsic sin
C Declaration error for size: unknown intrinsic function
C      intrinsic size
      
      real a(5)
      do 10 i = 1, 5
        a(i) = real(i)
   10 continue
      print '(I5)', size(a)
      end

After compiling with f2c test.f -ext, the translated C file, contains the following declarations:

    /* Local variables */
    static real a[5];
    static integer i__;
    extern doublereal size_(real *);

@Pap No worries mate! And you gave me good tips to improve my code. Thanks!

A cursory search through documents I could find online, doesnā€™t appear to support this:

  • Fortran 90/95 Programming Manual (PDF, 279 KB)

    The size of the array (the number of elements it contains, size_a in the example below), is determined in the subroutine using the intrinsic function size. size (array, dim) returns the number of elements along a specified dimension dim. The argument dim is optional. If it not specified, size sums the number of elements in each dimension.

  • Fortran 90 Handbook: Complete ANSI/ISO Reference (PDF, 1.5 MB); from 1992, in all examples shown, size returns a scalar.
  • Lahey Fortran 90 Language Reference (PDF, 2.5 MB); pg. 214-215

    [ā€¦] The result is a scalar of type default INTEGER. If dim is present, the result is the extent of
    dimension dim of array. If dim is absent, the result is the number of elements in array.

A colleague of mine preserved a working 90ā€™s O2 workstation from Silicon Graphics. Iā€™ll remind myself to check what the Fortran compiler does (assuming itā€™s still on there :crossed_fingers:) and write back to you. Trust, but verify, they sayā€¦

1 Like

The main compiler at work back then was Digital/Compaq Fortran. The GNU/Linux Fortran 90 compilers were at an early stage at the time, but I had access to Vast/F90 and a special free version of the NAG Fortran compiler around that time or a little later.
The Lahey compiler was out of my reach, this was not a compiler for common mortals. :laughing:

The Russian aphorism that became more known after the Chernobyl TV mini series, where it is mentioned in probably one of the best moments for the show. Now I feel like the KGB is after me. :rofl:
Iā€™m kidding of course, I am also curious about what you will find. I donā€™t quite remember all the details, but I do know for sure that all the Fortran tutors at that time had to warn students about sizeā€™s peculiarity. Once Fortran 2003 was accessible, I never used size without the dim optional argument, for that very reason.

When I do a google search for ā€œgfortran sizeā€, I get this hit: SIZE - The GNU Fortran Compiler which has the incorrect fortran version number.

The link Properties and attributes of arrays ā€” Fortran Programming Language provides the correct description, but it also attributes this function to f95 rather than f90. [this sentence was corrected in an edit]

I would also say that the quoted statement

is a little ambiguous, at least enough to catch your attention and read it twice. Those words might mean sum(shape(x)), which of course is not correct. The correct return value is product(shape(x)). The shape() function of course does return an array.

Finally I got my account sorted out. I created a bug report for this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110826

1 Like

You may be remembering the function shape that always returns an array.
Cheers

1 Like

Thanks!

Iā€™m sorry to reopen this hot discussion.
It seems this bug has not been fixed yet. Even worse, from the link one could see that

Assignee: 	Not yet assigned to anyone 
1 Like

I havenā€™t tried it yet, but it looks like they fixed this.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110826#c5

That escaleted quickly.

2 Likes