The CARG function passes a numeric or logical argument by value, rather than using the Fortran standard of passing arguments by reference. If the argument is of type CHARACTER, the CARG function will convert the argument to a C string. CARG can only be used as an actual argument when invoking a subroutine or function.
Syntax
CARG (item)
item is an INTENT(IN) named data object of any intrinsic type except COMPLEX and four-byte LOGICAL. It is the data object for which to return a value.
If the argument is numeric or logical, the value of item is placed on the calling stack, rather than its address.
If the argument is of type CHARACTER, the Fortran length descriptor is removed and the character string is null terminated.
The C data type of the result is shown in Table 8.
|
Fortran Type |
Fortran Kind |
C type |
|---|---|---|
|
INTEGER |
1 |
signed char |
|
INTEGER |
2 |
signed short int |
|
INTEGER |
4 |
signed long int |
|
REAL |
4 |
float |
|
COMPLEX |
4 |
must not be passed by value; if passed by reference (without CARG) it is a pointer to a structure of the form: struct complex { float real_part; float imaginary_part;}; |
|
LOGICAL |
1 |
unsigned char |
|
LOGICAL |
4 |
must not be passed by value or by reference |
|
CHARACTER |
1 |
char * |
Example
real :: a=1.0 character :: c="howdy" i=my_c_function(carg(a)) ! a is passed by value call my_c_subroutine(carg(c)) ! c is passed as a C string