From mboxrd@z Thu Jan 1 00:00:00 1970 From: Toon Moene To: egcs@cygnus.com Subject: ss-199805171100UTC oddity with statement functions (Fortran) Date: Mon, 18 May 1998 08:51:00 -0000 Message-id: <9805181439.AA06196@moene.indiv.nluug.nl> X-SW-Source: 1998-05/msg00633.html 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.