Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 ディスカッション

Memory Access Violation

gelarimer
ビギナー
628件の閲覧回数

I have been troubleshooting a memory access
violation and found the following line of code
in a function that initializes the OPENFILENAME
structure:

OFN%LpStrFileTitle = LOC(gszFileTitle//"*.txt"C)

Where gszFileTitle is a Global variable.

code should have been:

OFN%LpStrFileTitle = NULL

LOC(gszFileTitle//"*.txt"C) does not produce a
compiler error, so I assume that a temporary memory
location is created to hold the string
gszFileTitle//"*.txt"//ACHAR(0). However, after the
function returns I assume the address becomes invalid.

If the paragraph above is correct it would explain
the memory access violation.

Any comments would be appreciated.

0 件の賞賛
2 返答(返信)
Steven_L_Intel1
従業員
628件の閲覧回数
Your understanding is correct. You are allowed to take LOC(expression), but the expression is on the routine local stack and the address is no longer valid after the routine exits.
gelarimer
ビギナー
628件の閲覧回数
Thanks Steve. The program ran for a couple of years before the memory access violations started to occur.Apparently a minor change in another routinecausedthe fn. GetOpenFileName(OFN) to overwrite a critical memory location. That location was the invalid address retained by OFN%LpStrFileTitle. The OFN structure is alsoGlobal.
返信