[net.lang.f77] Adjustable Arrays

woods@hao.UUCP (Greg Woods) (03/07/85)

  I've run across what appears to be yet another bug in the 4.2BSD F77 
compiler, and I'm curious to see if the anyone else out there has seen this.
The code in question looks like:

      dimension buf(102,51),nbuf(5)
      nbuf(2)=102
      nbuf(3)=51
c
c  code here initializes the buf array
c
      write(6,*) buf
      call sub(buf,nbuf)
      stop
      end
      subroutine sub(buf,nbuf)
      dimension nbuf(5)
      dimension buf(nbuf(2),nbuf(3))
      write(6,*) buf
      return
      end

  The problem comes in when I attempt to use the elements of a dummy array
as variable dimension declarators for another dummy array. I did not find
anything in the standard which prohibits this; did I miss something? On our
VAX 11/750, this produces incorrect code, as the wrong values are written
inside the subroutine. The funny thing is, if I compile the subroutine
-g, it works properly.
   Questions: Why does it matter if I compile it -g? I was under the impression
that the generated code was the same except for the added symbol table. 
Second question: is this even legal according to the standard? Any comments
welcome.

--Greg
-- 
{ucbvax!hplabs | allegra!nbires | decvax!noao | harpo!seismo | ihnp4!noao}
       		        !hao!woods

CSNET: woods@NCAR  ARPA: woods%ncar@CSNET-RELAY
   
     "Please don't dominate the rap Jack, if you got nothing new to say..."

sjc@angband.UUCP (Steve Correll) (03/10/85)

>       subroutine sub(buf,nbuf)
>       dimension nbuf(5)
>       dimension buf(nbuf(2),nbuf(3))
>       write(6,*) buf
>       return
>       end
>
> Second question: is this even legal according to the standard?

It may be illegal. Section 5.1.1.1, "Form of a Dimension Declarator",
page 5-2 of ANSI X3.9-1978 says: "A dimension bound expression must not
contain a function or array element reference." Of course, one would hope
the compiler would complain rather than emitting bad code.
-- 
                                                           --Steve Correll
sjc@s1-b.ARPA, ...!decvax!decwrl!mordor!sjc, or ...!ucbvax!dual!mordor!sjc