This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: ISO C binding and character variables
Hi again,
one has to be careful though; assuming the following file (based on the
original example):
--------------------
subroutine param_test(my_char) bind(c)
use iso_c_binding
character(c_char), value :: my_char
if(my_char /= c_char_'y') stop 'error'
end subroutine param_test
--------------------
If now "my_char" is a scalar variable ("char my_char_") then one needs
to remember this later on in the program; otherwise one does the same
mistake as NAG f95 and produces:
----------------
void param_test(char my_char_)
{
if ( *my_char_!=121)
__NAGf90_stop("error");
}
----------------
That is: One uses "*my_char" although my_char is not a pointer. And as
Steve E. has shown simply assuming "char[]" does not work on IA64 HP-UX
and thus one needs to go through all trans-* and make sure it works.
Who has ever claimed that ISO C Binding is trivial?
As post script:
I filled this as PR32732
As another post script:
The extra length parameter(s) is/are not nice, but harmless: It/They
always come(s) last in the argument list and can therefore easily be
ignored. And while the parameter is present in the argument list, it is
never used.
I'm almost sure, however, that someone will find a platform or scenario
where this fails.
Tobias