This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 16 bits char string from C to FORTRAN


Americo Barbosa da Cunha Junior wrote:
> I'm  calling a FORTRAN subroutine in a ANSI C program. The subroutine
> has the following prototype:

> FORTRAN:
> 
>       SUBROUTINE CKINIT (LENIWK, LENRWK, LENCWK, LINC, LOUT, ICKWRK,
>      1                   RCKWRK, CCKWRK, IFLAG)
>
> The char* string passed to CKINIT must be at least 16 bits
> (CHARACTER*16) or the program is finished with the error message:
> 
>           CHARACTER LENGTH OF CCKWRK MUST BE AT LEAST 16
> 

As written before by Steve: "CHARACTER*16" is an old way to write
"CHARACTER(len=16)" which denotes a string of 16 characters, each of
them one-byte wide (8 bits).

Thus you can pass a "char *" to the subroutine.

NOTE: Fortran does not have the concept of zero ('\0') terminated
strings; thus if you need to read the string from C, you should take
care of the zero termination yourself.

NOTE 2: If the string in Fortran is not written as
  CHARACTER*16
but as CHARACTER(*), most Fortran compilers expect an additional "int *"
argument with the string length, which follows all other arguments, i.e.
in your case the IFLAG argument. One can still pass the stringlength for
CHARACTER*16, but it also works if one does not do so.

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]