How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
--abc<<
Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
A full, self-contained example would be helpful for somebody trying to
help (especially since you say "link", which seems weird).
But take a look at
https://gcc.gnu.org/onlinedocs/gfortran/Naming-and-argument-passing-conventions.html
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile
time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
It is generally a good idea to use ISO C binding in new code, it
is what it was introduced for.
But you might also find
https://gcc.gnu.org/onlinedocs/gfortran/Interoperability-Options.html
of interest.
On Thu, 02 Jan 2025 02:27:54 -0600, Lynn McGuire wrote:
How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile
time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
As Thomas as indicated, ISO C binding was introduced into the
Fortran standard to address your needs. But, if you want to
go old school with gcc/gfortran, then
% cat aa.c
#include <string.h>
void
string_(char *s, int *slen)
{
strncpy(s, "abc", *slen);
}
% cat bb.f90
program foo
external :: string
character(len=10) str
call string(str, len(str))
print *, '>>' // str //'<<'
end program foo
% ~/work/bin/gcc -c aa.c
% gfcx -o z bb.f90 aa.o
% ./z
>>abc<<
On 1/2/2025 12:40 PM, Steven G. Kargl wrote:
On Thu, 02 Jan 2025 02:27:54 -0600, Lynn McGuire wrote:
How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile
time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
As Thomas as indicated, ISO C binding was introduced into the
Fortran standard to address your needs. But, if you want to
go old school with gcc/gfortran, then
% cat aa.c
#include <string.h>
void
string_(char *s, int *slen)
{
strncpy(s, "abc", *slen);
}
% cat bb.f90
program foo
external :: string
character(len=10) str
call string(str, len(str))
print *, '>>' // str //'<<'
end program foo
% ~/work/bin/gcc -c aa.c
% gfcx -o z bb.f90 aa.o
% ./z
>>abc<<
Isn't the character string length variable "slen" a value parameter and size_t type ?
How do you send a fortran character string from GCC to GFortran ?
Isn't the character string length variable "slen" a value parameter and size_t
type ?
On 2025-01-02 23:38, Lynn McGuire wrote:
Isn't the character string length variable "slen" a value parameter and size_t
type ?
Depends: gfortran 8 and subsequent versions use size_t, older versions and other
compilers use int AFAIK.
I guess, handling strings beyond 2GB is not a particular strength of Fortran anyway, so I don't know why that change was made.
Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
How do you send a fortran character string from GCC to GFortran ?
I cannot get this to link. I can do the reverse, send a fortran
character string from Gfortran to GCC.
A full, self-contained example would be helpful for somebody trying to
help (especially since you say "link", which seems weird).
But take a look at
https://gcc.gnu.org/onlinedocs/gfortran/Naming-and-argument-passing-conventions.html
I do have the additional complication that I do not know the length of
the fortran character string being sent from GCC to Gfortran at compile
time, only run time. So that is a character*(*) string.
I am not using the ISO C binding.
It is generally a good idea to use ISO C binding in new code, it
is what it was introduced for.
But you might also find
https://gcc.gnu.org/onlinedocs/gfortran/Interoperability-Options.html
of interest.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 149:59:56 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
438 files (115M bytes) |
Messages: | 2,410,967 |