- #1
eddyq
- 8
- 0
Is there a way to use C functions from Watcom Fortran?
To use C functions with Watcom Fortran, you must first declare the C functions in your Fortran code using the EXTERNAL
statement. Then, you can use the CALL
statement to call the C functions within your Fortran code.
Yes, you can pass Fortran variables to C functions by using the VALUE
or REF
attribute in the EXTERNAL
statement. The VALUE
attribute passes the value of the variable, while the REF
attribute passes the address of the variable.
To handle C function return values in Fortran, you can use the FUNCTION
statement to declare the C function as a function in your Fortran code. Then, you can use the RETURN
statement to assign the return value of the C function to a Fortran variable.
Yes, there are some limitations to using C functions with Watcom Fortran. For example, you cannot pass Fortran arrays directly to C functions. Instead, you must use the TRANSFER
statement to convert the array to a temporary C array.
Yes, you can mix C and Fortran code in the same file as long as you use the appropriate syntax for each language. For example, C functions must be enclosed in extern "C"
blocks, and Fortran code must be enclosed in PROGRAM
or SUBROUTINE
blocks.