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, or make use of the standards-compiliant VALUE attribute. For example:

  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 for more details.