- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
For a while ago there were some posts about the RANDOM_NUMBER being a PURE procedure or not and so on. I wonder if there been any developments lately in this area or if somebody can give me an advice on the following:
I have the following simple code:
PROGRAM something
REAL :: a(10)
PRINT*, rd(a)
CONTAINS
ELEMENTAL FUNCTION rd(x) result(y)
REAL, INTENT(IN) :: x
REAL :: y
CALL RANDOM_NUMBER(y)
END FUNCTION
REAL, INTENT(IN) :: x
REAL :: y
CALL RANDOM_NUMBER(y)
END FUNCTION
END PROGRAM something
And as you can guess my CVF6.6c tells me "Hit the road, Jack".
But the same code works in Lahey.
Can I make this work in CVF6.6c and if the answer is "yes", then how?
Best regards ... Hossein
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nothing has changed - RANDOM_NUMBER, like all of the intrinsic subroutines other than MVBITS, is not PURE. The Lahey compiler you are using is simply not detecting this; earlier versions of CVF didn't either.
The definition of a PURE routine excludes side-effects and requires that every call with the same arguments return the same result. RANDOM_NUMBER fails on both counts.
You can cheat if you want - declare an explicit interface to MY_RANDOM_NUMBER that declares it as PURE, then write an external routine MY_RANDOM_NUMBER that calls RANDOM_NUMBER. But don't complain here if the compiler decides to do an optimization that is valid on PURE routines but not non-PURE routines.
The definition of a PURE routine excludes side-effects and requires that every call with the same arguments return the same result. RANDOM_NUMBER fails on both counts.
You can cheat if you want - declare an explicit interface to MY_RANDOM_NUMBER that declares it as PURE, then write an external routine MY_RANDOM_NUMBER that calls RANDOM_NUMBER. But don't complain here if the compiler decides to do an optimization that is valid on PURE routines but not non-PURE routines.

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