Making Calls to C Functions Work

When you pass an argument to a subprogram call, the usual Fortran convention is to pass the address of the argument. Many C functions expect arguments to be passed as values, however, not as addresses. For these arguments, specify them as %VAL(argument) in the call to C, as follows:

  MEMBLK = MALLOC(1024)    ! Wrong, passes the address of the constant
  MEMBLK = MALLOC(N)       ! Wrong, passes the address of the variable
 
  MEMBLK = MALLOC(%VAL(1024)) ! Right, passes the value 1024
  MEMBLK = MALLOC(%VAL(N))    ! Right, passes the value of the variable

See Passing Arguments By Reference or By Value and %VAL and %REF in the XL Fortran Language Reference for more details. IBM Copyright 2003