Changes relating to the value attribute

Changes relating to the value attribute

We're currently checking our code prior to upgrading from to Apart from syntax changes for subroutines with no arguments and bind(c) evrything seems to be okay. For example

subroutine mysub bind(c)

no longer compiles, instead we have

subroutine mysub() bind(c)

Yesterday we found that some functions that are C and used in the Fortran code through asssociated function pointers now need the bind(c) attribute. However it isn't true of all such functions. For example with the interface below

    abstract interface 
    subroutine updateloadsetvector(loadcaseid,berror,igid,dval)
    use iso_c_binding
    integer(c_int),value,intent(in) :: loadcaseid,igid
    logical*4,intent(out):: berror
    real(c_double),value,intent(in) :: dval
    end subroutine  updateloadsetvector
    end interface

the arguments are not passed by value, whereas if bind(c) is added then the arguments are passed by value. But this isn't true of all such functions; with the interface below

    abstract interface 
    subroutine getdefaultgroup(key,igrflag,zcurgrp)
    use iso_c_binding 
    integer(c_int), value, intent(in) :: key
    integer(c_int),intent(out):: igrflag(*)
    character*(*), intent(out):: zcurgrp
    end subroutine getdefaultgroup
    end interface 

the bind(c) attribute is not needed in order to get pass-by-value. It is almost as if the value attribute is being ignored when there are no arrays or character strings in the argument list. I have tried at /assume:std_value but that has not effect in this case.

So although I've fixed the problem by adding a sprinkling of bind(c)s I'd like to understand the change - or report the new behaviour as a bug.



4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

subroutine mysub bind(c)

In fixed form source that looks like a normal (non-bind) function statement, hence the parentheses are syntactically required.

The change in VALUE for non-bind(c) procedures has been discussed here recently.  It was intentional.

According to that thread the (erroneous) behaviour of value is unchanged unless the /assume:std_value argument is given, in which case the correct behaviour is invoked. What it doesn't explain what change was made between v12 and v14 of the compiler. I'm sure the effect is due to the indirection caused by associating functions through function pointers since we use the value attribute in many places without problems and it may well be that the new behaviour is correct, I'd just like to understand what change was made and why so that I can explain it to my boss when he asks!

If you didn't use BIND(C), then nothing should have changed. As explained in the other thread, we intended to make a change to conform to the standard in 14, but made it optional. However, it seems we missed at least one case where the VALUE attribute is inconsistently applied.

Can you show a small but complete example that shows the problem? If you were relying on the incorrect behavior, where without BIND(C) VALUE causes pass-by-value, then /standard-semantics would just make it worse.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today