(something) /= something ?
- From: "FJRA" <a19980403@xxxxxxxxxxx>
- Date: 28 Jun 2005 16:49:23 -0700
Hi, I have found a problem wiht a function I made, and I have made a
small test program of this. I don't know if I am doing something wrong.
It gives me a runtime error if I don't put an extra () to an argument
in a function, or any other operation. So, I need to do an operation
before sending it to the function.
Well, I show you the code:
!
-----------------------------------------------------------------module
modpruebafuncion
implicit none
contains
! -----------------------------------------------------------------!
Obtiene el tamaño en dígitos (incluyendo el signo menos) de un
número entero.
PURE INTEGER FUNCTION tamanoentero(numero)
integer, intent(IN) :: numero
tamanoentero =
merge(1,0,numero<0)+ceiling(log10(1+max(1d0,abs(real(numero,8)))))
END FUNCTION tamanoentero
! -----------------------------------------------------------------!
Convierte un número entero en una cadena. Usa formato I0.
FUNCTION enteroacadena(numero)
integer, intent(IN) :: numero
character(LEN=tamanoentero(numero)) :: enteroacadena
write(enteroacadena, '(I0)') numero
END FUNCTION enteroacadena
end module modpruebafuncion
!
-----------------------------------------------------------------program
pruebafunciondefinicion
use modpruebafuncion
implicit none
integer i
character(11) :: cadena
i = 10
cadena = enteroacadena(-1) ! works fine!
write(*,*) cadena
cadena = enteroacadena(i) ! works fine!
write(*,*) cadena
cadena = enteroacadena(i+1) ! doesn't work fine!
write(*,*) cadena
end program pruebafunciondefinicion
! -----------------------------------------------------------------
It compiles fine in CVF 6.5 and in g95. gfortran cannot compile it.
If I run the g95 executable, it works fine, and I get:
>g95 pruebafunciondefinicion.f90
>a
-1
10
11
in CVF:
>df pruebafunciondefinicion.f90
Compaq Visual Fortran Optimizing Compiler Version 6.5
Copyright 2000 Compaq Computer Corp. All rights reserved.
pruebafunciondefinicion.f90
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/subsystem:console
/entry:mainCRTStartup
/ignore:505
/debugtype:cv
/debug:minimal
/pdb:none
C:\DOCUME~1\FRODRI~1\CONFIG~1\Temp\obj12D.tmp
dfor.lib
libc.lib
dfconsol.lib
dfport.lib
kernel32.lib
/out:pruebafunciondefinicion.exe
>pruebafunciondefinicion
-1
10
forrtl: severe (157): Program Exception - access violation
Image PC Routine Line Source
pruebafunciondefi 004012A0 Unknown Unknown Unknown
pruebafunciondefi 00435D59 Unknown Unknown Unknown
pruebafunciondefi 00428084 Unknown Unknown Unknown
KERNEL32.dll 79461AF6 Unknown Unknown Unknown
and in gfortran:
>gfortran pruebafunciondefinicion.f90 -o b.exe
pruebafunciondefinicion.f90: In function 'enteroacadena':
pruebafunciondefinicion.f90:12: internal compiler error: in
gfc_finish_var_decl,
at fortran/trans-decl.c:436
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
OK, BUT, if a use
character(LEN=tamanoentero((numero))) :: enteroacadena
instead of
character(LEN=tamanoentero(numero)) :: enteroacadena
I don't get any error in CVF. So, it means I need to operate "numero"
before send it to the function ??? Is it correct? Is it a bug? Or is
just non standard my implementation?
I hope I have explained myself good.
Thanks in advance,
Francisco Javier Rodríguez Arias
PS. (just to let you know, I always use FJRA, instead of my name,
because it is shorter :).
.
- Follow-Ups:
- Re: (something) /= something ?
- From: James Van Buskirk
- Re: (something) /= something ?
- Prev by Date: how to use fortran modules in c++
- Next by Date: Re: (something) /= something ?
- Previous by thread: how to use fortran modules in c++
- Next by thread: Re: (something) /= something ?
- Index(es):