- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I do for this dynamically allocating array? I want to allocate it in subroutine not in main program. Thanks!
I got the error message in the following code: Unhandled exception at 0x00401064 in Test.exe: 0xC0000005: Access violation reading location 0x00000020.
I got the error message in the following code: Unhandled exception at 0x00401064 in Test.exe: 0xC0000005: Access violation reading location 0x00000020.
PROGRAM MAIN
REAL,ALLOCATABLE::M(:)
CALL NEW(M)
STOP
END
SUBROUTINE NEW(M1)
REAL,ALLOCATABLE::M1(:)
INTEGER i,N
N=100
ALLOCATE(M1(N))
do i=1,N
M1(i)=i
ENDDO
RETURN
END
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I compiled this in CVF and got
:\F90\allocatetest\allocatetest.f90(23) : Warning: In the call to NEW, actual argument #1 does not match the type and kind of the corresponding dummy argument.
CALL NEW(M)
-----------------^
when built and run, an access violation occurred that caused DevStudio to crash and exit.
:\F90\allocatetest\allocatetest.f90(23) : Warning: In the call to NEW, actual argument #1 does not match the type and kind of the corresponding dummy argument.
CALL NEW(M)
-----------------^
when built and run, an access violation occurred that caused DevStudio to crash and exit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Requirement of the Fortran Standard: The caller of a procedure that takes allocatable arguments must provide an explicit interface for the procedure.
The main program has M declared as allocatable, but that is not enough to tell the compiler that subroutine NEW takes an allocatable argument. Indeed, it is possible to do the allocation in the main program and pass the argument to a subroutine; in that case, from the latter's point of view, there would be no distinction between an argument that was dynamically allocated and an argument that was allocated at compile time.
The main program has M declared as allocatable, but that is not enough to tell the compiler that subroutine NEW takes an allocatable argument. Indeed, it is possible to do the allocation in the main program and pass the argument to a subroutine; in that case, from the latter's point of view, there would be no distinction between an argument that was dynamically allocated and an argument that was allocated at compile time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This needs a complete f90 interface (interface block, module subroutine, CONTAINS subroutine). Is your point that the compiler should tell you this explicitly? If you used ifort, you would have to be willing to set /gen-interfaces in hopes of getting such a message. I do find the documentation confusing, as ifort -help still says you must use both /gen-interfaces and /warn-interfaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, in current versions of ifort, /warn:interface is the option and /gen-interface is obsolete. It is also the default in newly created Visual Studio projects and has been since version 11.0.

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