Compatibility of array indexing for gcc 3.4.6 and gcc 4.4.7?
Janus Weil
janus@gcc.gnu.org
Fri Nov 1 11:29:00 GMT 2013
Hi Stefan,
> I am working with a large research center in particle physics. We have large
> software packages written in fortran, which we used until now with
> "scientific linux 5", on 32-bit and with a rather old compiler
> (gcc version 3.4.6)
> Now we have to migrate to a more recent distribution "scientific linux 6",
> the compiler will be somewhat more recent (gcc version 4.4.7)
>
> We have a problem with our software backwards-compatibility.
> One of the problems we found is the following: when using a large negative
> integer as an array index, the code produced by the old compiler would
> silently return the first element of the array. The code produced by the new
> compiler instead results in a segmentation fault. Some example code is
> attached below.
> My question is: is there a way to restore the old way of treating the large
> negative array indexes, perhaps using some special compiler option?
why do you want to restore that behavior?
If have have an array "table(1:100)" which you access with a negative
index, I would argue that something is wrong is your program. Btw I
also don't see why "table(-2147483647)" would be the same as
"table(1)".
There are many points where backward compatibility with g77 is
important for gfortran, but IMHO this is not one of them (basically
because the program is invalid). Why not modify your code such that it
actually uses "table(1)" if that is what you're expecting to get ... ?
Cheers,
Janus
> ====== begin example code =======
> program arraycompat32bit
> implicit none
> integer index
> real table(100),t
> do index=1,100
> table(index)=100*index+3.1415926535
> enddo
> index=-2147483647
> C the next statement works silently on scientific linux 5, 32-bit
> C with gcc version 3.4.6 20060404 (Red Hat 3.4.6-4.1)
> C (t is set to table(1))
> C but it crashes on scientific linux 6, 64 bit (segmentation fault)
> C with gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
> t=table(index)
> write(*,*)t
> end
> ====== end example code =========
>
> Old compiler configuration:
> ----------------------------
> Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
> --infodir=/usr/share/info --enable-shared --enable-threads=posix
> --disable-checking --with-system-zlib --enable-__cxa_atexit
> --disable-libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj
> --host=i386-redhat-linux
> Thread model: posix
> gcc version 3.4.6 20060404 (Red Hat 3.4.6-4.1)
>
> result of uname -a:
> -------------------
> Linux h1island408b 2.6.18-274.12.1.el5PAE #1 SMP Tue Nov 29 11:48:41 EST
> 2011 i686 i686 i386 GNU/Linux
>
>
> New compiler configuration:
> ----------------------------
> Using built-in specs.
> Target: x86_64-redhat-linux
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
> --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
> --enable-bootstrap --enable-shared --enable-threads=posix
> --enable-checking=release --with-system-zlib --enable-__cxa_atexit
> --disable-libunwind-exceptions --enable-gnu-unique-object
> --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
> --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
> --enable-libgcj-multifile --enable-java-maintainer-mode
> --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
> --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
> --build=x86_64-redhat-linux
> Thread model: posix
> gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
>
> result of uname -a:
> --------------------
> Linux h1farm18 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 20:37:17 CST 2013
> x86_64 x86_64 x86_64 GNU/Linux
More information about the Fortran
mailing list