- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
The snippet below passes the expression (A) and the actual array A. Thus, there is no argument aliasing involved. As I understand, (i) the expression references A, (ii) is evaluated completely before invoking the subroutine, and (iii) changes to A won't affect the expression.
Although I am using assumed-shape array in subroutine Method, I am wondering where is the expression stored? i.e. is there something going on stack? I don't see the array temporary being created message when I use /check:arg_temp_created flag.
Abhi
----
Module OM
Implicit None
Contains
Subroutine Method(n, A, m, B)
Integer, Intent(IN) :: n
Real, Intent(IN) :: A(:)
Integer, Intent(OUT) :: m
Real, Intent(OUT) :: B(:)
!Real :: A(:), B(:)
m = 2*n
B = 3*A
End Subroutine Method
End Module OM
Program Test_ExpressionArgument
Use OM
Implicit None
Integer :: n = 2, m
Real :: A(5) = -1.0
Real :: c
Call Method(n, (A), m, A)
Print *, A
End Program Test_ExpressionArgument
The snippet below passes the expression (A) and the actual array A. Thus, there is no argument aliasing involved. As I understand, (i) the expression references A, (ii) is evaluated completely before invoking the subroutine, and (iii) changes to A won't affect the expression.
Although I am using assumed-shape array in subroutine Method, I am wondering where is the expression stored? i.e. is there something going on stack? I don't see the array temporary being created message when I use /check:arg_temp_created flag.
Abhi
----
Module OM
Implicit None
Contains
Subroutine Method(n, A, m, B)
Integer, Intent(IN) :: n
Real, Intent(IN) :: A(:)
Integer, Intent(OUT) :: m
Real, Intent(OUT) :: B(:)
!Real :: A(:), B(:)
m = 2*n
B = 3*A
End Subroutine Method
End Module OM
Program Test_ExpressionArgument
Use OM
Implicit None
Integer :: n = 2, m
Real :: A(5) = -1.0
Real :: c
Call Method(n, (A), m, A)
Print *, A
End Program Test_ExpressionArgument
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is creating a stack temp. You don't get the warning when you have explicitly asked for an expression.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. I guess then if the array size is large, one may get stack overflow error. Is the /heap-arrays only way to avoid it?
Also, I get a warning when I use assumed-sized arrays, I believe that is correct behavior. Is that right?
Abhi
Also, I get a warning when I use assumed-sized arrays, I believe that is correct behavior. Is that right?
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. If you are forcing a copy to be made, it has to go somewhere.
What warning for assumed-size arrays?
What warning for assumed-size arrays?
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