character function return length specified by dummy arg

character function return length specified by dummy arg

Bild des Benutzers 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?

5 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers 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...

Anlagen: 

AnhangGröße
Herunterladen apache-interfaces.zip1.63 MB
Bild des Benutzers 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
Bild des Benutzers David Mccabe

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

Thank you

Bild des Benutzers 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

Melden Sie sich an, um einen Kommentar zu hinterlassen.