Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Using the 'value' attribute

Simon_Geard
New Contributor I
1,425 Views
module mymod
    implicit none
    type my_t
	integer :: a = 3
    end type my_t
	
contains
    subroutine by_value(i,m) bind(c,name='BY_VAL')
	use iso_c_binding
	integer(c_int), intent(in), value :: i
	type(my_t), intent(out) :: m
	m%a = i
    end subroutine by_value
		
end module mymod

program test
	use mymod
	implicit none
	integer :: i
	type(my_t) :: m

	i = 5
	
	call by_val(i,m)
	print *, m%a
	
	call by_value(i,m)
	print *, m%a
	
end program test

 

> ifort tc.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.180 Build 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 

Microsoft (R) Incremental Linker Version 11.00.60610.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:tc.exe
-subsystem:console
tc.obj

> tc
  1060107240
           5

The above code shows the inconsistency. If I remove the output argument 'm' in the calls then both output values are '5' as I'd expect. I get the same result with Version 14.0.1.139 Build 20131008.

 

0 Kudos
22 Replies
jimdempseyatthecove
Honored Contributor III
271 Views

That alien is from Bluto

Jim Dempsey

0 Kudos
JohnNichols
Valued Contributor III
271 Views

I could swear that alien is the spitting image of my brother - but maybe only after a few beers

0 Kudos
Reply