character function return length specified by dummy arg

character function return length specified by dummy arg

Imagen de David Mccabe

The following code snippet seems to be working fine in debug and causing access violations in release:

!------------------------------------------
! c_string to character string conversion.
function f_string(cStr,fStr_size) result (fStr)
type(c_string) :: cStr
integer :: fStr_size
character(len=fStr_size) :: fStr
!call c_string_to_character_string(fStr,cStr)
end function f_string

 Perhaps it is illegal to have the return length specified by dummy arg?

publicaciones de 5 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de David Mccabe

The code snippet above work fine, the problem must be introduced elsewhere. This forms part of a test project in where I am trying out type bound procedures for the first time. I have uploaded the project files...

Adjuntos: 

AdjuntoTamaño
Descargar apache-interfaces.zip1.63 MB
Imagen de Steve Lionel (Intel)

David, you have been very naughty. You used BIND(C) to call a STDCALL routine, papering over the error by including the @n name decoration in the external names in the BIND clause. This causes stack corruption.

In Intel Fortran, BIND(C) cannot be used to call STDCALL routines - only the default C convention is allowed.

Steve
Imagen de David Mccabe

Ah! I was unaware this was the case. The code now works fine.

Thank you

Imagen de Steve Lionel (Intel)

In general, any time you find yourself adding the @n suffix to an external name string to fix up a linking error, that should be a red flag that you're probably doing something wrong.

Steve

Inicie sesión para dejar un comentario.