public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* ss-199805171100UTC oddity with statement functions (Fortran)
@ 1998-05-18  8:51 Toon Moene
  1998-05-19  9:03 ` Craig Burley
  0 siblings, 1 reply; 7+ messages in thread
From: Toon Moene @ 1998-05-18  8:51 UTC (permalink / raw)
  To: egcs

Consider the following Fortran code:

      program stmfun
      integer n
      values(i,j) = val((i-1)*n+j)
      end

where `values' is a statement function (Fortran's idea of a macro,  
but then at the compiler, not the preprocessor, level) that's not  
used, accessing an array `val' that's not defined.

Now watch this:

% g77 -v -O2 stmfun.f
g77 version 0.5.22-19980315
 gcc -v -O2 -xf77 stmfun.f -xnone -lf2c -lm
Reading specs from  
/usr/local/lib/gcc-lib/m68k-next-nextstep3/2.7.2.3.f.2/specs
gcc version 2.7.2.3.f.2
 /usr/local/lib/gcc-lib/m68k-next-nextstep3/2.7.2.3.f.2/f771  
stmfun.f -fset-g77-defaults -quiet -dumpbase stmfun.f -O2 -version  
-fversion -o /usr/tmp/cc006183.s
GNU F77 version 2.7.2.3.f.2 (68k, MIT syntax) compiled by GNU C  
version 2.7.2.3.f.2.
GNU Fortran Front End version 0.5.22-19980315 compiled: Mar 15 1998  
19:35:34
 as -o /usr/tmp/cc0061831.o /usr/tmp/cc006183.s
 ld -lcrt0.o  
-L/usr/local/lib/gcc-lib/m68k-next-nextstep3/2.7.2.3.f.2  
-L/usr/local/lib /usr/tmp/cc0061831.o -lf2c -lm -lgcc -lsys_s -lgcc

% /usr/snp/bin/g77 -v -O2 stmfun.f
Reading specs from  
/usr/snp/lib/gcc-lib/m68k-next-nextstep3/egcs-2.91.29/specs
gcc version egcs-2.91.29 19980517 (gcc2 ss-980502 experimental)
 /usr/snp/lib/gcc-lib/m68k-next-nextstep3/egcs-2.91.29/f771  
stmfun.f -fset-g77-defaults -quiet -dumpbase stmfun.f -O2 -version  
-fversion -o /usr/tmp/cc006188.s
GNU F77 version egcs-2.91.29 19980517 (gcc2 ss-980502 experimental)  
(m68k-next-nextstep3) compiled by GNU C version egcs-2.91.29  
19980517 (gcc2 ss-980502 experimental).
GNU Fortran Front End version 0.5.22-release
 as -o /usr/tmp/cc0061881.o /usr/tmp/cc006188.s
 /usr/snp/lib/gcc-lib/m68k-next-nextstep3/egcs-2.91.29/collect2  
-lcrt0.o -L/usr/snp/lib/gcc-lib/m68k-next-nextstep3/egcs-2.91.29  
-L/usr/snp/m68k-next-nextstep3/lib -L/usr/snp/lib  
/usr/tmp/cc0061881.o -lf2c -lm -lgcc -lsys_s -lgcc
/bin/ld: Undefined symbols:
_val_
collect2: ld returned 1 exit status

Anyone with a bright idea ?

Note that this is not contrary to the Standard - I have seen this  
with Digital's Fortran compiler too, and as far as I understand the  
Fortran 90 Handbook (as close to the Standard as I can get) there is  
nothing to prevent the compiler to generate code for `values' (and  
hence trying to access `val') even if it's not used.

Note 2: For complete understanding of this example one should know  
that in Fortran an identifier, followed by something between  
parentheses, *that isn't declared as an array* is an implicitly  
declared function call :-) :-)

Cheers,
Toon.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-05-20 20:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-18  8:51 ss-199805171100UTC oddity with statement functions (Fortran) Toon Moene
1998-05-19  9:03 ` Craig Burley
1998-05-19 21:17   ` Toon Moene
1998-05-19 21:17     ` Craig Burley
1998-05-20  9:26       ` Dave Love
1998-05-20 12:32       ` Dave Love
1998-05-20 20:48       ` ss-199805171100UTC oddity with statement functions; was Fortran,now C Toon Moene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).