In vs2013 debug mode, I set a break-point just before I cann an interger function with a character string argument but when I step into the function the value of the argument has changed.I'm sending a character(120) variable and I reference the routine using a 'use mStrlnth' statement. The module is:
Module mStrLnth Implicit None Contains Integer(4) Function StrLnth (myStr) ! This function finds the length of a string which may be zero length ! if nothing is in the string but spaces, tabs, or ""C marks character(*),Intent(inout):: myStr character(512):: fld ! I create this variable only for debugging Integer(4):: i, sl, j, kk sl = 0 i = len_trim(myStr) fld = myStr(1:i) // achar(0) do j = 1, i kk = ichar(fld(j:j)) if ((kk >= 33) .and. (kk <= 122)) then sl = j else exit end if end do StrLnth = sl return end function StrLnth end module mStrLnth
The calling routine snippet is:
use mStrLnth ... iret = RegQueryValueEx( hKey, "Data4"C, NULL, NULL, LOC(Buff), LOC(iLen)) if (iret /= ERROR_SUCCESS) then fmt = "Data4"C write(LnBuff,'(i4)') __LINE__ Go to 998 end if if (iLen > 5) Then ! and so remove trailing blanks myBuff = " "C myBuff = Buff(1:iLen) iLen = StrLnth(myBuff)
I'm sending something like '123456789'
and I'm receiving something like '4' followed by a few garbage characters'
Any ideas would be appreciated.
I'm compiling and running x64 builds with vs2013 on a 64bit Win 10 machine using an Intel i7-4770 processor with 32GB RAM and using IVF Parallel Studio XE Composer Edition v2017 r2.
It would help if you were to provide a complete main program that calls your function. It occurs to me that the function code is not living up to its billing. For example, if the argument is ' X ', which contains four blanks before and after 'X', your function would return 0 instead of 5, because of the premature EXIT.