- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm getting an access violation while copying value from one variable to another variable. Here is the error message I receive:
Unhandled exception at 0x00494a5a in TEST.exe: 0xC0000005: Access violation writing location 0x004fa7d4.
And here is the code. The error appears while running the following line of code:
Full subroutine below:
Any ideas? Maybe I have a setting incorrect or something else?
Unhandled exception at 0x00494a5a in TEST.exe: 0xC0000005: Access violation writing location 0x004fa7d4.
And here is the code. The error appears while running the following line of code:
[bash]STR(I:I) = ACHAR(IACHAR(STR(I:I)) - DEL)[/bash]
Full subroutine below:
[bash] SUBROUTINE UPPERCASE(STR) IMPLICIT NONE CHARACTER(LEN=*), INTENT(IN OUT) :: STR INTEGER :: I, DEL DEL = IACHAR('a') - IACHAR('A') DO I = 1, LEN_TRIM(STR) IF (LGE(STR(I:I),'a') .AND. LLE(STR(I:I),'z')) THEN STR(I:I) = ACHAR(IACHAR(STR(I:I)) - DEL) END IF END DO RETURN END SUBROUTINE UPPERCASE [/bash]
Any ideas? Maybe I have a setting incorrect or something else?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please supply a main program which calls this routine and gets the error.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When it comes to string conversion there are a ton of code avaialbe in public domain. Just google it. Maybe the following will help you to debug (from a c.l.f. discussion).
People also use the INDEX function for case conversion. This is independent of the character representation (ASCII, DISPLA. EBCDIC, etc.). It works as:
Take a look at http://flibs.sourceforge.net/.
HTH.
[bash]MODULE STRINGS IMPLICIT NONE !====================================================================== FUNCTION TOUPPER(sString) CHARACTER(*),INTENT(IN):: sString CHARACTER(LEN=LEN(sString)):: TOUPPER INTEGER:: i, iAsc TOUPPER=sString DO i=1,LEN(sString) iAsc=ICHAR(sString(i:i)) IF (iAsc.GE.97 .AND. iAsc.LE.122) TOUPPER(i:i)=CHAR(iAsc-32) END DO END FUNCTION TOUPPER !====================================================================== FUNCTION TOLOWER(sString) CHARACTER(*),INTENT(IN):: sString CHARACTER(LEN=LEN(sString)):: TOLOWER INTEGER:: i, iAsc TOLOWER=sString DO i=1,LEN(sString) iAsc=ICHAR(sString(i:i)) IF (iAsc.GE.65 .AND. iAsc.LE.90) TOLOWER(i:i)=CHAR(iAsc+32) END DO END FUNCTION TOLOWER !====================================================================== END MODULE STRINGS [/bash]
People also use the INDEX function for case conversion. This is independent of the character representation (ASCII, DISPLA. EBCDIC, etc.). It works as:
[bash]elemental function str_toupper ( inpstring ) result( outstring ) implicit none character(len = 26), parameter:: LOWER_CASE = 'abcdefghijklmnopqrstuvwxyz' character(len = 26), parameter:: UPPER_CASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ! -- Argument and result character(len = *), intent (in) :: inpstring character(len = LEN(inpstring)) :: outstring ! -- Local variables integer :: ii, n ! -- Copy input string outstring = inpstring ! -- Loop over string elements do ii = 1, LEN(outstring) ! -- Find location of letter in lower case constant string n = INDEX( LOWER_CASE, outstring( ii:ii ) ) ! -- If current substring is a lower case letter, make it upper case if ( n /= 0 ) outstring( ii:ii ) = UPPER_CASE( n:n ) end do end function str_toupper[/bash]
Take a look at http://flibs.sourceforge.net/.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please supply a main program which calls this routine and gets the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I seeyou are converting in place; are you passing a variable?
Or was it a string-constantsuch as:
CALL UPPERCASE ("Hello!")
By default, string-constants are put into read-onlymemory.
--- Lorri
Or was it a string-constantsuch as:
CALL UPPERCASE ("Hello!")
By default, string-constants are put into read-onlymemory.
--- Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Yeah, good suggestion. I took the EXE in question and ripped everything out. Left all the settings the same, but ripped everything out to call just that subroutine and it works. So, I need to find out what is offending it. Thanks.
Lorri,
Just an FYI - I'm passing a variable and it works in the stripped down version that way. Thanks for the advice.
--Dan
Yeah, good suggestion. I took the EXE in question and ripped everything out. Left all the settings the same, but ripped everything out to call just that subroutine and it works. So, I need to find out what is offending it. Thanks.
Lorri,
Just an FYI - I'm passing a variable and it works in the stripped down version that way. Thanks for the advice.
--Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Access violation writing location" means you wereattempting to write to anaddress that is eitherwrite protected or not mapped to your virtual address (and is not automatically mapped asin first write circumstance). Your code contains a read of the string location STR(I:I)prior to write and youdid not receive "Accessviolation reading location". Therefore it appears that STR(I:) was readable but not writeable. Depending onthe version of Windowsyou canhave virtual memory pages that are marked Execute Only (implies Read Only) as well as Read Only. Pages that you cannot write to might, for example, contain string literals. On your program that exhibits this error, add a WRITE(*,*) STR before your DO loop. See what comes out.
Jim Dempsey
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page