This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Different behavior of C and Fortran Code
- From: Philippe Schaffnit <P dot Schaffnit at access dot rwth-aachen dot de>
- To: Sebastian Hegler <sebastian at broken-by-design dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Wed, 24 May 2006 12:11:22 +0200
- Subject: Re: Different behavior of C and Fortran Code
- Organization: Access e.V.
- References: <BF66CE39-216A-482F-8FE4-7D50645725D0@broken-by-design.com>
Hi!
I've stumbled on somthing similar before: C and Fortran are both
behaving right (from my understanding), only that initialising a
variable when declaring it in Fortran implies it to be "SAVED" ('static'
in C, I think), which is consistant with the outputs you get...
Please correct me if I'm wrong...
Cheers!
Philippe
Sebastian Hegler wrote:
>
> Hi!
>
> Attached you'll find 2 source files in C and F90, which essentially
> do the same. Except that C acts "correctly" IMHO.
> Can you tell me which of the two acts correctly?
>
> Thanks in advance!
>
> Sebastian
>
> $ gcc test.c && ./a.out
> 2
> 3
> 2
> 3
> 2
> 3
> 2
> $ gfortran test.f90 && ./a.out
> 2
> 3
> 3
> 4
> 4
> 5
> 5
>
> $ gcc -v
> Using built-in specs.
> Target: powerpc-apple-darwin8
> Configured with: /private/var/tmp/gcc/gcc-5250.obj~12/src/configure --
> disable-checking -enable-werror --prefix=/usr --mandir=/share/man --
> enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg]
> [^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --
> build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --
> target=powerpc-apple-darwin8
> Thread model: posix
> gcc version 4.0.1 (Apple Computer, Inc. build 5250)
>
> $ gfortran -v
> Using built-in specs.
> Target: powerpc-apple-darwin7.9.0
> Configured with: ../gcc/configure --prefix=/usr/local/gfortran --
> enable-languages=c,fortran --with-gmp=/tmp/gfortran-20060512/
> gfortran_libs --enable-bootstrap
> Thread model: posix
> gcc version 4.2.0 20060512 (experimental)
>
> ------------------------------------------------------------------------
> Name: test.c
> test.c Type: unspecified type (application/octet-stream)
> Encoding: 7bit
>
> Name: test.f90
> test.f90 Type: unspecified type (application/octet-stream)
> Encoding: 7bit